如果您通过 selenium 将屏幕截图保存到托管代理。您可以通过Publish Build Artifacts task将测试屏幕截图发布到 azure 管道构建工件。请参见下面的示例:
测试方法:
webDriver = new ChromeDriver();
webDriver.Manage().Window.Maximize();
webDriver.Navigate().GoToUrl(test_url);
Screenshot screenshot = ((ITakesScreenshot)webDriver).GetScreenshot();
# create a screenshots directory to save the screenshots.
Directory.CreateDirectory("screenshots");
string attachmentsPath = Directory.GetCurrentDirectory() + "\\" +"screenshots"+"\\" +
"testName1.png";
# save the screenshot to the screenshots directory.
screenshot.SaveAsFile(attachmentsPath);
Assert.AreEqual(webDriver.Title,"Google");
webDriver.Quit();
上面的代码会将屏幕截图保存到文件夹文件screenshots
夹中。
然后您可以添加复制文件任务以将屏幕截图复制到文件夹$(build.artifactstagingdirectory)
- task: CopyFiles@2
displayName: 'Copy Files to: $(build.artifactstagingdirectory)'
inputs:
SourceFolder: '$(system.defaultworkingdirectory)'
Contents: '**\screenshots\**'
TargetFolder: '$(build.artifactstagingdirectory)'
flattenFolders: true
接着。添加发布构建工件任务以发布屏幕截图以构建工件。
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: screenshots'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
ArtifactName: screenshots
管道构建完成后。您可以直接从摘要页面下载屏幕截图。