我能够创建一个新的测试运行并更新每个测试步骤状态,最后完成自动测试运行。我使用C#库文件将所有这些文件都用于VSTS。
此外,我目前正在将屏幕截图附加到测试步骤结果。我可以看到屏幕截图附加到“运行”选项卡下的“测试步骤”,但上传不完整,无法看到屏幕截图被加载。
以下是用于附加屏幕截图的代码:
ITestAttachment attachment = stepResult.CreateAttachment(screenShotPath);
stepResult.Attachments.Add(attachment);
Also please find the screenshot attached to understand my problem much better.
感谢您的帮助
答案 0 :(得分:0)
使用下面的代码,它会将附件上传到测试步骤,当我检查测试结果时,图像显示不正确(与您相同),但一分钟后,它会正确显示。因此,您现在可以检查图像是否正确显示。
int testpointid = 56;
var u = new Uri("https://XXX.visualstudio.com");
var c = new VssClientCredentials();
c.Storage = new VssClientCredentialStorage(storageKind: "VssApp", storageNamespace: "VisualStudio");
TfsTeamProjectCollection _tfs = new TfsTeamProjectCollection(u, c);
_tfs.EnsureAuthenticated();
ITestManagementService test_service = (ITestManagementService)_tfs.GetService(typeof(ITestManagementService));
ITestManagementTeamProject _testproject = test_service.GetTeamProject("{proejct}");
ITestPlan _plan = _testproject.TestPlans.Find(89);
ITestRun testRun = _plan.CreateTestRun(false);
testRun.Title = "apiTest2";
ITestPoint point = _plan.FindTestPoint(testpointid);
testRun.AddTestPoint(point, test_service.AuthorizedIdentity);
testRun.Save();
testRun.Refresh();
ITestCaseResultCollection results = testRun.QueryResults();
ITestIterationResult iterationResult;
foreach (ITestCaseResult result in results)
{
iterationResult = result.CreateIteration(1);
foreach (Microsoft.TeamFoundation.TestManagement.Client.ITestStep testStep in result.GetTestCase().Actions)
{
ITestStepResult stepResult = iterationResult.CreateStepResult(testStep.Id);
stepResult.Outcome = Microsoft.TeamFoundation.TestManagement.Client.TestOutcome.Passed; //you can assign different states here
Microsoft.TeamFoundation.TestManagement.Client.ITestAttachment attachment = stepResult.CreateAttachment(@"{image path}");
stepResult.Attachments.Add(attachment);
iterationResult.Actions.Add(stepResult);
}
iterationResult.Outcome = Microsoft.TeamFoundation.TestManagement.Client.TestOutcome.Passed;
result.Iterations.Add(iterationResult);
result.Outcome = Microsoft.TeamFoundation.TestManagement.Client.TestOutcome.Passed;
result.State = TestResultState.Completed;
result.Save(true);
}
testRun.State = Microsoft.TeamFoundation.TestManagement.Client.TestRunState.Completed;
results.Save(true);