microsoft test manager - TFS API: How to get attachments from shared steps? -
this see in test results in test manager: attachments (1) on test steps (in case - on shared step). (2) on result level. in report i'm working on, can extract information attachments (2), fail information (1). suggestions?
in debugger can see, steps iterated, can see, i.e. "verify stuff" string etc, step has 0 attachments.
for reference, of code using extract test case results:
foreach (itestcaseresult testcaseresult in resutlstodisplay) { project.testcases.find(test.id); var testrun = testcaseresult.gettestrun(); var testplanentry = project.testplans.find(testrun.testplanid); var artifacts = testcaseresult.queryassociatedworkitemartifacts(); if (testplanentry.name != testplan) continue; var testresult = new testresult // custom class { testconfiguration = testcaseresult.testconfigurationname, testrun = testrun.id, datecreated = testrun.datecreated, datestarted = testrun.datestarted, datecompleted = testrun.datecompleted, result = testcaseresult.outcome.tostring(), testresultcomment = testrun.comment, runby = testcaseresult.runby == null ? "" : testcaseresult.runby.displayname, build = testrun.buildnumber ?? "" }; foreach (var iteration in testcaseresult.iterations) { var iterationresult = testresult.clone(); iterationresult.resultattachmenthtml = getattachments(iteration.attachments, testcase.testcaseid.tostring(), string.empty, iteration.iterationid.tostring()); // here attachments of type 2 iterationresult.iteration = iteration.iterationid; iterationresult.iterationcomment = iteration.comment; foreach (var step in steps) { var stepcopy = step.clone(); iterationresult.steps.add(stepcopy); var actionresult = iteration.findactionresult(stepcopy.teststep); if (actionresult == null) continue; stepcopy.result.comment = actionresult.errormessage; stepcopy.result.result = actionresult.outcome.tostring(); stepcopy.result.attachmenthtml = getattachments(actionresult.attachments, testcase.testcaseid.tostring(), step.number, iteration.iterationid.tostring()); // here not attachments of type 1 - why? } config.testcaseresult.testresults.add(iterationresult); } } //end foreach testcaseresult in resutlstodisplay
i think figured out eventually.
the itestcaseresult contains itestiterationresultcollection iterations.
the itestiterationresult contains testactionresultcollection of itestactionresult.
itestactionresult can either iteststepresult or isharedstepresult.
if iteststepresult, has attachments collection right there.
if isharedstepresult, however, has own testactionresultcollection. 1 have iterate find if each member has attachments.
the code iterate on steps, including shared steps, looks this:
foreach (itestiterationresult iteration in testcaseresult.iterations) { var iterationresult = testresult.clone(); iterationresult.resultattachmenthtml = getattachments(iteration.attachments, testcase.testcaseid.tostring(), string.empty, iteration.iterationid.tostring()); iterationresult.iteration = iteration.iterationid; iterationresult.iterationcomment = iteration.comment; foreach (itestactionresult action in iteration.actions) { if (action iteststepresult) { getstepresults(steps, action, iterationresult, iteration, getattachments, testcase, false); } else if (action isharedstepresult) { isharedstepresult result = action isharedstepresult; foreach (var sharedaction in result.actions) { if (sharedaction iteststepresult) { getstepresults(steps, sharedaction, iterationresult, iteration, getattachments, testcase, true); } } } } 
Comments
Post a Comment