我需要检索每个共享步骤的状态(Passed \ Failed \ No run)。我能够访问共享步骤标题和预期结果,我需要检索结果和注释。我知道可以从ITestIterationResult中检索这些细节以进行测试执行,但有人可以指导我使用代码。请帮我解决这个问题,以下是我到目前为止的情况。
public ISharedStep tstSharedStep {get;私人集; }
public ISharedStepReference tstSharedStepRef {get;私人集; }
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, @"<[^>]+>| ", "").Trim();
resultData.ExpectedResult = Regex.Replace(tstSharedTestStep.ExpectedResult, @"<[^>]+>| ", "").Trim();
}
}
else {
// regular step action
}
}
答案 0 :(得分:1)
我能够找到解决方案,并且认为我可以分享它......
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);
}
}
}