0

I want to run my coded ui test cases from a WPF application. However, when I initialize playback and call the test method, I am getting an error that the TestContext is NULL. Could anyone pls suggest if execution of coded ui test via WPF application is possible? Also, how can I access the TestContext in this approach as the test cases are data driven and I need to access TestContext.

Thanks.

4
  • Possible duplicate of Executing coded UI test from a standalone application Commented Oct 29, 2015 at 8:56
  • The requirement is to execute coded ui test from wpf application directly through code not using test agent or bat file. Commented Oct 29, 2015 at 14:17
  • Read the suggested duplicate again. There are several approaches offered, only one of them mentions "bat" and "agent". Please edit the question to show any additional requirements. Commented Oct 29, 2015 at 14:21
  • I am calling the Playback.Initialize, TestMethod and Playback.Cleanup in the right order. But the TestContext, when accessed, is null. Commented Oct 29, 2015 at 14:26

1 Answer 1

3

This a behavior question of test runners

TestConext is populated at run time of the "TestHarness/TestRunner". Its is an abstract class that in Visual Studio the process is called QAagent32.exe that supplies an implemented version for this based upon what your test method and class requires of it, e.g. Iterating data rows from a Excel Worksheet, TFS TestCase parameter data table; Coded UI, Unit Test. If you want to use what is already used in Visual Studio you can just call GetType() on it, and research from there for its fully qualified type used. However, IF that class type isn't available you'll have to implement a concrete class that fully implements TestContex

Then in code you can do like the following:

PlayBack.Initialize();
var yourTestClass = new YourUniqueClassTests();
yourTestClass.TestContext = TestConextFactory.GetImplimentation();
yourTestClass.TestMethodThatsImportant();

Now if your using the DataSource attribute on your test methods you will probably have to use reflection to pull that info.

var attribute= yourTestClass.GetType()
                            .GetMethod("TestMethodThatsImportant")
                            .GetCustomAttributes(typeof(DataSourceAttribute),false)[0] 
                             as DataSourceAttribute;

This should be able to get that data for you. Once you have it you could add logic to decide on what type of TestContext object you implement to set on the test class.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.