Completed
Last Updated: 08 May 2014 10:52 by ADMIN
ADMIN
Cody
Created on: 04 Apr 2014 20:27
Type: Feature Request
3
TestResult.Parent is null
Put this code into a child test:

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

            string parentName = Convert.ToString(result.Parent.Name);
            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
        }

Now run the parent test that calls this child test.
Expected: The test to pass
Actual: 
>>> Test-as-Step 'TestResultParentIssue\Child.tstest' log starts:

------------------------------------------------------------
'4/4/2014 3:24:55 PM' - Detected custom code in test. Locating test assembly: Telerik Troubleshooting.dll.
'4/4/2014 3:24:55 PM' - Assembly Found: F:\Dropbox\Support Issues\Telerik Troubleshooting\Telerik Troubleshooting\bin\Telerik Troubleshooting.dll
'4/4/2014 3:24:55 PM' - Loading code class: 'Telerik_Troubleshooting.Child'.
------------------------------------------------------------
'4/4/2014 3:24:56 PM' - Error attempting to execute a Test As Step. Details:
'4/4/2014 3:24:56 PM' - System.NullReferenceException: Object reference not set to an instance of an object.
   at Telerik_Troubleshooting.Child.OnAfterTestCompleted(TestResult result) in f:\Dropbox\Support Issues\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)

<<< Test-as-Step 'TestResultParentIssue\Child.tstest' log ends.

Upon closer inspection you will find that TestResult.Parent is null.
1 comment
ADMIN
Daniel Djambov
Posted on: 08 May 2014 10:49
Telerik: the current requested usage of the extension override cannot be achieved like this. When overriding the 'OnAfterTestCompleted' method from a coded step in .tstest, it lives in the context of the 'BaseWebAiiTest', which provides only 'TestResult' object, but the 'TestResult.Parent'  property gives access to the RunResult object, which is applicable in test list execution context only. What you can do instead is override the whole execution extension 'IExecutionExtension' (here is more information how to do this http://docs.telerik.com/teststudio/user-guide/code-samples/general/execution-extensions.aspx) which exposes another context of 'OnAfterTestCompleted' method called 'ExecutionContext' and within it you can have all information about the test being executed. In your case if you want to have the name of the parent test only logged, you should build execution extension library with code like this:
using System;
using System.Runtime.Serialization;
using System.Windows.Forms;
using System.IO;
using System.Data;

using ArtOfTest.WebAii.Design.Execution;

namespace OverrideExecutionExtension
{
    public class Class1 : IExecutionExtension
    {
        public void OnAfterTestCompleted(ExecutionContext executionContext, TestResult result)
        {
            //Log only failures of main tests, not called Test As Steps    
            if (executionContext.ExecutingTestAsStep==false)
            {
                //do no logging for test as steps
                    string msg = string.Format("   {0} test: '{1}' on date: '{2}'", result.Result.ToString().ToUpper(), executionContext.Test.Path, System.DateTime.Now);
                    {
                    //do what you need to do with executionContext.
                    }
                }
            }
        
    }
}