The ExecutionContext is null. Initialize has not been called yet or it failed.
Sample of code from the common tstest class:
public void actionLogin()
{
//other code
this.ExecuteTest("Actions\\acLogin.tstest");
//other code
}
Sample of code from the outside tstest class:
Common.actionLogin();
11 Answers, 1 is accepted
Thank you for contacting us.
Unfortunately I am not able to reproduce this behavior.
Please send us the project so we can see the exact scenario and debug it.
If you don't feel convenient to share the project here in a public forum I can send you a drop box link.
Hope to hear from you soon.
Regards,
Boyan Boev
Telerik
Thank you for contacting us.
Unfortunately I am not able to reproduce this behavior.
Please send us the project so we can see the exact scenario and debug it.
If you don't feel convenient to share the project here in a public forum I can send you a drop box link.
Hope to hear from you soon.
Regards,
Boyan Boev
Telerik
Sorry for the delay. Attached is a sample project that demonstrates the issue I am encountering. If you quick execute the test named "CallingTest.tstest", you will see the following error:
Failure Information:
~~~~~~~~~~~~~~~
Exception thrown executing coded step: '[CallingTest_CodedStep] : New Coded Step'.
InnerException:
System.NullReferenceException: The ExecutionContext is null. Initialize has not been called yet or it failed.
at ArtOfTest.WebAii.Design.BaseWebAiiTest.get_ExecutionContext()
at ArtOfTest.WebAii.Design.BaseWebAiiTest.ExecuteTest(String relativeTestPath)
at Telerik_Troubleshooting.Common.actionSearch() in c:\Test Studio Projects\Telerik Troubleshooting\Telerik Troubleshooting\Common.cs:line 48
at Telerik_Troubleshooting.CallingTest.CallingTest_CodedStep() in c:\Test Studio Projects\Telerik Troubleshooting\Telerik Troubleshooting\CallingTest.tstest.cs:line 89
As originally stated, we are attempting to execute shared tests from code, but from a common class. The reason for this being that we've had to incorporate logic into determing exactly which actions to execute in some instances. Rather than adding this logic into every test that needs it, we created a common class that when needed, we can just pass a few data values into and it can determine which action to run as a result. It's not ideal for the design of Test Studio, but it was the best solution for our problem.
Thank you for providing the sample project. The problem is that the Common class hasn't been fully initialized. A BaseWebAiiTest object doesn't get fully initialized except when it is instantiated by our framework. As a result of this improper initialization the ExecutionContext stored in the BaseWebAiiTest object hasn't been set properly. That's why you're getting the NulReferenceException when you try to run this.ExecuteTest("Search.tstest") in actionSearch method.
What you should be doing instead is creating your class which is not based on BaseWebAiiTest. You can pass in the "this" object, i.e. an already initialized BaseWebAiiTest object, from your Parent test into your own class and use that. For example:
public
class
Common2
{
BaseWebAiiTest activeTest;
public
Common2(BaseWebAiiTest callingTest)
{
activeTest = callingTest;
}
public
void
actionSearch()
{
activeTest.ExecuteTest(
"Search.tstest"
);
}
}
Then you can use this class from your Parent test in a coded step like this:
Common2 com =
new
Common2(
this
);
com.actionSearch();
Also please rename Common to something else (e.g. Common2). We use Common class already in the Framework and it won't work with that name.
Attaching the fixed project.
Let me know if this helps.
Regards,
Boyan Boev
Telerik
Glad I could help.
If you need further assistance, please let us know.
Regards,
Boyan Boev
Telerik
Hey Boyan,
i have the same exception appeared but the thing is my project is not a test project it is a wpf application and i added the ArtofTest dlls to it to be able to execute or run the web tests from the wpf application the code is like :
namespace TA
{
/// <summary>
/// Interaction logic for TestScripts.xaml
/// </summary>
public partial class TestScripts : System .Windows .Controls .Page
{
public TestScripts()
{
InitializeComponent();
CommonFunctions cf = new CommonFunctions();
cf.TC_1();
}
}
public class CommonFunctions : BaseWebAiiTest
{
public CommonFunctions()
{
}
[CodedStep(@"Execute test 'Login'")]
public void TC_1()
{
this.ExecuteTest(@"path");
}
}
}
but each time a get same error NullReferenceException :The ExecutionContext is null. Initialize has not been called yet or it failed
how can i make The ExecutionContext not null???
Thanks,
Hend
Please use a separate, test project, for the test cases. Thank you!
In order to run tests you can use the Test Studio Quick Execution or the Visual Studio's Test Explorer.
Regards,
Konstantin Petkov
Telerik
Hi Boyan,
Thanks for the solution. Even i encountered this issue and this thread helped me.
Thanks,
VVP
Team,
I followed the steps provided above and its working but when I do this while providing manager object, test fails.
Scenario :
(1) Inside Class A and Method A, I am creating an Instance of a class and inside I am passing the manager object like as shown below
Global_Methods GM = new Global_Methods();
GM.Launch_Read_Excel(Project_path,foldername,this.Manager);
(2) Inside the class "Class1" and method "actionSearch", I am trying to execute "this.executetest(<test_path>);" which is calling different test and below is the code :
public class Class1
{
BaseWebAiiTest activeTest;
public Class1(BaseWebAiiTest callingTest)
{
activeTest = callingTest;
}
public void actionSearch()
{
activeTest.ExecuteTest("Financials Panel\\World.tstest");
}
}
(3) And in "Launch_Read_Excel" method, i am calling below code
Class1 cl = new Class1();
cl.actionSearch();
Issue : Below is the Error Log
Failure Information: ~~~~~~~~~~~~~~~Exception thrown executing coded step: 'Driver Script'.InnerException:System.NullReferenceException: The ExecutionContext is null. Initialize has not been called yet or it failed. at ArtOfTest.WebAii.Design.BaseWebAiiTest.get_ExecutionContext() at ArtOfTest.WebAii.Design.BaseWebAiiTest.ExecuteTest(String relativeTestPath) at RaaS_Sample_Abdul.Class1.actionSearch() in d:\My Backup\04-07-16\RaaS_Project\Entity\WebTest.tstest.cs:line 34 at RaaS_Sample_Abdul.Global_Methods.Launch_Read_Excel(String PP, String FN, Manager manager) in d:\My Backup\04-07-16\RaaS_Project\Generic_Functions\Global_Methods.tstest.cs:line 748
Thanks
Abdul
Could you please create a sample project where I can reproduce this issue and give you a solution?
Hope to hear from you soon.
Regards,
Boyan Boev
Telerik by Progress