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

12 posts, 0 answers
  1. Nick
    Nick avatar
    23 posts
    Member since:
    Nov 2013

    Posted 07 Mar 2014 Link to this post

    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();
  2. Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 13 Mar 2014 Link to this post

    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!
  3. Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 13 Mar 2014 Link to this post

    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!
  4. Nick
    Nick avatar
    23 posts
    Member since:
    Nov 2013

    Posted 01 Apr 2014 in reply to Boyan Boev Link to this post

    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.
  5. Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 04 Apr 2014 Link to this post

    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!
  6. Nick
    Nick avatar
    23 posts
    Member since:
    Nov 2013

    Posted 06 Apr 2014 in reply to Boyan Boev Link to this post

    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.
  7. Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 07 Apr 2014 Link to this post

    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!
  8. Hend
    Hend avatar
    9 posts
    Member since:
    Mar 2015

    Posted 29 Jun 2015 in reply to Boyan Boev Link to this post

    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

  9. Konstantin Petkov
    Admin
    Konstantin Petkov avatar
    1911 posts

    Posted 29 Jun 2015 Link to this post

    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!
  10. VVP
    VVP avatar
    61 posts
    Member since:
    Mar 2015

    Posted 30 Jul 2015 in reply to Konstantin Petkov Link to this post

    Hi Boyan,

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

    Thanks,

    VVP

  11. Abdul Khader
    Abdul Khader avatar
    22 posts
    Member since:
    Feb 2016

    Posted 28 Sep Link to this post

    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

  12. Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 03 Oct Link to this post

    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!
Back to Top