我正在尝试使用 VS 测试任务在 Azure DevOps 的“测试”选项卡中添加失败的测试附件。
我正在调用创建测试结果附件休息 api,
$AzureDevOpsPAT = {PAT}
$AzureDevOpsAuthenicationHeader = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($AzureDevOpsPAT)")) }
$result = Invoke-RestMethod -Uri https://dev.azure.com/{org}/{proj}/_apis/test/runs/$(runId)/results?api-version=6.0 -Headers $AzureDevOpsAuthenicationHeader -Method Get
#List all test result get the test result ID via result
foreach($Run in $result.value){
#Get the test result ID via result
If($Run.outcome -eq "Failed"){
$TestResultID = $Run.id
$Name=$Run.testCase.name
Write-Host $TestResultID $Name
#Add attachment via test run ID and test result ID
$TestResultAttachmentURL = "https://dev.azure.com/{org}/{proj}/_apis/test/Runs/$(runId)/results/$($TestResultID)/attachments?api-version=6.0-preview.1"
$body =@"
{
"stream": "abc",
"fileName": "$(System.DefaultWorkingDirectory)/$Name.png",
"comment": "Test attachment upload",
"attachmentType": "GeneralAttachment"
}
"@
$TestResultAttachmentResult = Invoke-RestMethod -Uri $TestResultAttachmentURL -ContentType "application/json" -Body $body -Headers $AzureDevOpsAuthenicationHeader -Method POST
}
}
我看不到相应的屏幕截图,如果我单击附件选项卡中的 .png 文件,则会显示黑花,
虽然我也在我的代码中捕获屏幕截图,
protected void StopWebDriver()
{
if (WebDriver != null)
{
string path = Directory.GetCurrentDirectory() + "\\" + BaseConfig.TestCaseName + ".png";
((ITakesScreenshot)WebDriver).GetScreenshot().SaveAsFile(path, ScreenshotImageFormat.Png);
WebDriver.Close();
WebDriver.Quit();
}
}
谁能告诉我怎样才能看到截图?