Given that I have a ITestCase
object obtained like so
ITestCase tc = project.TestCases.Find(2034);
Where project
is an object of type ITestManagementTeamProject
obtained by
TfsTeamProjectCollection tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(tfsLocation));
ITestManagementService testService = tfs.GetService<ITestManagementService>();
return testService.GetTeamProject(projectName);
How do I get all the shared step references(don't even know if there was one in the first place) for that particular test case, considering that I don't have any prior state knowledge about that test case.
Please help.
There is a ISharedStepReference Interface to call a shared step from a test case. You just need to use FindSharedStep method return the shared step definition from the server. A sample code for your reference:
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, @"<[^>]+>| ", "").Trim();
resultData.ExpectedResult = Regex.Replace(tstSharedTestStep.ExpectedResult, @"<[^>]+>| ", "").Trim();
}
}
else {
// regular step action
}
}