Azure开发人员:屏幕快照未显示在“附件"选项卡中 [英] Azure devops: Screenshot are not showing in attachment tab
问题描述
我正在尝试使用VS测试任务在Azure DevOps的测试"选项卡中添加失败的测试附件.
我正在呼叫
尽管我也在代码中捕获了屏幕截图,
受保护的void StopWebDriver(){如果(WebDriver!= null){字符串路径= Directory.GetCurrentDirectory()+"\\"+ BaseConfig.TestCaseName +".png";((ITakesScreenshot)WebDriver).GetScreenshot().SaveAsFile(path,ScreenshotImageFormat.Png);WebDriver.Close();WebDriver.Quit();}}
任何人都可以告诉我如何查看屏幕截图吗?
根据我的测试,屏幕截图可能显示在管道->中.测试->附件标签.
您可以使用PowerShell脚本生成Base64文件流,而不是对文件流进行硬编码.
这里是一个例子:
$ file = [IO.File] :: ReadAllBytes(" filepath \ $ Name.png")$ Base64file = [转换] :: ToBase64String($ file)回声$ Base64file$ token ="PAT"$ url =""https://dev.azure.com/{org}/{proj}/_apis/test/Runs/$(runId)/results/$($TestResultID)/attachments?api-version=6.0-预览.1"$ token = [System.Convert] :: ToBase64String([[System.Text.Encoding] :: ASCII.GetBytes(:$($ token)")))$ JSON ="{`"stream`":`"$ Base64file`",```" fileName`" ;:`" $ Name.png`" ;,`评论":测试附件上传",`"attachmentType`":`"GeneralAttachment`"}"$ response = Invoke-RestMethod -Uri $ url -Headers @ {Authorization ="Basic $ token"} -Method Post -Body $ JSON -ContentType application/json
另一方面,您可以直接尝试使用扩展名 I am trying to add failed test attachments in the Test tab in Azure DevOps using VS test task. I am calling the Create Test Result Attachment rest api, I cant see the respective screenshot, the black flower is showing if I click on .png file in the attachment tab,
Though I am capturing a screenshot in my code too, Can anyone please tell me how can I see screenshots? Based on my test , the screenshot could show in the Pipeline -> Test -> Attachment tab. You could use the PowerShell Script to generate the Base64 file Stream instead of hardcode the file stream. Here is an example: On the other hand, you could directly try to use the Publish screenshots for test failure task from the extension Publish test result screenshot. In addition, in order to confirm whether the image you uploaded is valid, you can also download and check whether it is the correct content. Update: To get the Test case name in a string, you could refer to this sample:
这篇关于Azure开发人员:屏幕快照未显示在“附件"选项卡中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!$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
}
}
protected void StopWebDriver()
{
if (WebDriver != null)
{
string path = Directory.GetCurrentDirectory() + "\\" + BaseConfig.TestCaseName + ".png";
((ITakesScreenshot)WebDriver).GetScreenshot().SaveAsFile(path, ScreenshotImageFormat.Png);
WebDriver.Close();
WebDriver.Quit();
}
}
$file= [IO.File]::ReadAllBytes("filepath\$Name.png")
$Base64file= [Convert]::ToBase64String($file)
echo $Base64file
$token = "PAT"
$url="https://dev.azure.com/{org}/{proj}/_apis/test/Runs/$(runId)/results/$($TestResultID)/attachments?api-version=6.0-preview.1"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))
$JSON = "
{
`"stream`": `"$Base64file`",
`"fileName`": `"$Name.png`",
`"comment`": `"Test attachment upload`",
`"attachmentType`": `"GeneralAttachment`"
}"
$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Post -Body $JSON -ContentType application/json
$String= "ooo.iii.kkk.lll"
$a,$b,$c,$d = $String.Split(".",4)
echo $c