How can I access the outcome of shared steps of a test case

418 views Asked by At

I need to retrieve the status (Passed\ Failed\ No run) of each shared steps. I am able to access the shared step title and expected result, and I need to retrieve the outcome and the comment. I understand that these details can be retrieved from the ITestIterationResult(s) for that test execution, but could someone guide me with the code. Please help me out on this, given below is what i have so far.

public ISharedStep tstSharedStep { get; private set; }

public ISharedStepReference tstSharedStepRef { get; private set; }

foreach (ITestAction tstAction in tstCase.Actions)
        {
            tstSharedStep = null; 
            tstSharedStepRef = tstAction as ISharedStepReference;
                if (tstSharedStepRef != null)
                {
                    tstSharedStep = tstSharedStepRef.FindSharedStep();
                    foreach (ITestAction tstSharedAction in tstSharedStep.Actions)
                    {
                        ITestStep tstSharedTestStep = tstSharedAction as ITestStep;
                        resultData.Step = Regex.Replace(tstSharedTestStep.Title, @"<[^>]+>|&nbsp;", "").Trim();
                        resultData.ExpectedResult = Regex.Replace(tstSharedTestStep.ExpectedResult, @"<[^>]+>|&nbsp;", "").Trim();

                    }
                }
                else {
                 // regular step action
                }

}

1

There are 1 answers

0
Div On BEST ANSWER

I was able to find a solution to this, and thought i'd share it..

ISharedStep shared_step = null;
                                        ISharedStepReference shared_ref = act as ISharedStepReference;

                                        if (shared_ref != null)
                                        {
                                            shared_step = shared_ref.FindSharedStep();

                                            ITestActionResult actionResult = iteration.FindActionResult(act);
                                            if (actionResult is ISharedStepResult)
                                            {
                                                ISharedStepResult sharedStepResult = actionResult as ISharedStepResult;
                                                foreach (var shareTestActionResult in sharedStepResult.Actions)
                                                {
                                                    sharedData = new TestSharedResult();
                                                    sharedData.SharedStepOutcome = shareTestActionResult.Outcome.ToString();
                                                    sharedData.SharedStepComment = shareTestActionResult.ErrorMessage.ToString();

                                                    sharedResultDataList.Add(sharedData);
                                                }
                                            }
                                        }