This is a migrated thread and some comments may be shown as answers.

"The ExecutionContext is null" error triggered when calling TestAsStep from another TestAsSte

11 Answers 810 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Nick
Top achievements
Rank 1
Nick asked on 07 Mar 2014, 05:20 PM
I have a common tstest class that houses global logic used throughout all my tests.  I'm attempting to call a actionLogin method that runs a Test As Step from another test.  If I call this actionLogin() method from within the common tstest class, OR if I just copy/paste the code into the outside tstest class, the test runs as expected.  If I call this Common.actionLogin() method from outside of this particular common tsttest class, the following error is triggered:

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

Sort by
0
Boyan Boev
Telerik team
answered on 13 Mar 2014, 07:26 AM
Hello Nick,

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
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Boyan Boev
Telerik team
answered on 13 Mar 2014, 07:55 AM
Hello Nick,

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
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Nick
Top achievements
Rank 1
answered on 01 Apr 2014, 04:51 PM
Hi Boyan,

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.
0
Boyan Boev
Telerik team
answered on 04 Apr 2014, 02:33 PM
Hi NIck,

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
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Nick
Top achievements
Rank 1
answered on 06 Apr 2014, 07:46 PM
Thank you for the explanation and example, that was just what I needed.  I've corrected my common class and can now call Test As Steps without issue.
0
Boyan Boev
Telerik team
answered on 07 Apr 2014, 07:53 AM
Hi Nick,

Glad I could help.

If you need further assistance, please let us know.

Regards,
Boyan Boev
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Hend
Top achievements
Rank 1
answered on 29 Jun 2015, 10:46 AM

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

0
Konstantin Petkov
Telerik team
answered on 29 Jun 2015, 03:46 PM
Hi,

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
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
VVP
Top achievements
Rank 2
answered on 30 Jul 2015, 09:02 AM

Hi Boyan,

Thanks for the solution. Even i encountered this issue and this thread helped me.

Thanks,

VVP

0
Abdul Khader
Top achievements
Rank 1
answered on 28 Sep 2016, 01:32 PM

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

0
Boyan Boev
Telerik team
answered on 03 Oct 2016, 12:28 PM
Hi 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
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Nick
Top achievements
Rank 1
Answers by
Boyan Boev
Telerik team
Nick
Top achievements
Rank 1
Hend
Top achievements
Rank 1
Konstantin Petkov
Telerik team
VVP
Top achievements
Rank 2
Abdul Khader
Top achievements
Rank 1
Share this question
or