Unable to access TestResult.Parent properties from OnAfterTestCompleted in a test-as-step

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

    Posted 01 Apr 2014 Link to this post

    My project has a shared test-as-step that each of my other tests call.  This test-as-step has the following override that is attempting to use properties of the testresult parent/calling test name to add to the custom log we've created:

    public override void OnAfterTestCompleted(TestResult result)
    {
    base.OnAfterTestCompleted(result);

    string parentName = Convert.ToString(result.Parent.Name); //line 103
    string parentId = Convert.ToString(result.Parent.Id);
    string parentRootName = Convert.ToString(result.Parent.RootName);
    string fileName = Convert.ToString(result.Parent.FileName);

    \\custom code to write to the log
    }

    Each line in the above override that references the testresult.parent.* properties test trigger the following error:
    System.NullReferenceException: Object reference not set to an instance of an object.
       at CIS.TestStudio.WebAccess.Shared.Handler.OnAfterTestCompleted(TestResult result) in c:\tfs\CoreCM\Root\CIS.TestStudio.WebAccess\Shared\Handler.tstest.cs:line 103
       at ArtOfTest.WebAii.Design.Execution.ExecutionEngine.InternalExecuteTestIteration(Object codeBehindInstance, Boolean isDataDriven)
       at ArtOfTest.WebAii.Design.Execution.ExecutionEngine.ExecuteDataDrivenTest(Test test, BaseWebAiiTest codeInstance)
       at ArtOfTest.WebAii.Design.Execution.ExecutionEngine.InternalExecuteTest(Test test, TestResult initializationResult)
       at ArtOfTest.WebAii.Design.Execution.ExecutionEngine.ExecuteTestInCurrentContext(Test test)

    If this is not the correct way to access the name of the parent/calling test properties, is there a better way to do so through code?
  2. Nick
    Nick avatar
    23 posts
    Member since:
    Nov 2013

    Posted 01 Apr 2014 Link to this post

    I've attached a sample project showing the issue I'm experiencing.  If you quick execute the test named "Parent.tstest" in folder "TestResultParentIssue", you will see the following error:

    System.NullReferenceException: Object reference not set to an instance of an object.
       at Telerik_Troubleshooting.Child.OnAfterTestCompleted(TestResult result) in c:\Test Studio Projects\Telerik Troubleshooting\Telerik Troubleshooting\TestResultParentIssue\Child.tstest.cs:line 78
       at ArtOfTest.WebAii.Design.Execution.ExecutionEngine.InternalExecuteTestIteration(Object codeBehindInstance, Boolean isDataDriven)
       at ArtOfTest.WebAii.Design.Execution.ExecutionEngine.InternalExecuteTest(Test test, TestResult initializationResult)
       at ArtOfTest.WebAii.Design.Execution.ExecutionEngine.ExecuteTestInCurrentContext(Test test)
  3. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 04 Apr 2014 Link to this post

    Hello Nick,

    Bug confirmed. I've granted you some Telerik Points for reporting this to us. Why do you need those parameters in the child test? An alternative would be to store that data into a global C# variable while in the parent test which the child test can access.

    Regards,
    Cody
    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 06 Apr 2014 in reply to Cody Link to this post

    Thanks Cody.

    I originally needed it because I added custom logging that first checks for a logfile at "<path>\<testname>.txt" and either adds to it or creates it if it doesn't exist, then populates the run results in the file.  The problem I was having was that when I have a shared test that other tests call (shared.tstest), it would write the results to both the <path>\shared.txt file and the <path>\parenttest.txt log file.  I figured out a workaround, which was to just add a check to my execution extension dll that the test name was not "shared" prior to logging any events.  Now when a failure occurs in a shared test, the result propagates to the parent test so the results are still captured.
  5. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 07 Apr 2014 Link to this post

    Hello Nick,

    That sounds like a very good alternative. Thank you for the update.

    Regards,
    Cody
    Telerik
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
Back to Top