【发布时间】:2020-10-19 18:09:28
【问题描述】:
是否有一种简单的方法可以将 Robot Framework 生成的 XUNIT 样式测试结果的屏幕截图链接起来,并通过 Azure Pipelines 的发布测试结果任务将它们加载到测试选项卡中?
与他们处理 VSTS 结果文件的方式类似。
提前致谢。
【问题讨论】:
标签: python automated-tests robotframework azure-pipelines xunit
是否有一种简单的方法可以将 Robot Framework 生成的 XUNIT 样式测试结果的屏幕截图链接起来,并通过 Azure Pipelines 的发布测试结果任务将它们加载到测试选项卡中?
与他们处理 VSTS 结果文件的方式类似。
提前致谢。
【问题讨论】:
标签: python automated-tests robotframework azure-pipelines xunit
恐怕上面没有简单的方法来实现。
作为一种解决方法,您可以使用Create Test Result Attachment rest api 将屏幕截图更新为测试用例的附件。
POST https://dev.azure.com/{organization}/{project}/_apis/test/Runs/{runId}/Results/{testCaseResultId}/attachments?api-version=5.1-preview.1
为了使用上面创建测试结果附件rest api。您需要致电query test runs rest api 获取runId
GET https://dev.azure.com/{organization}/{project}/_apis/test/runs?buildIds={buildIds}&buildDefIds={buildDefIds}&api-version=5.1
然后你需要调用列表test results rest api来获取testCaseresultId
GET https://dev.azure.com/{organization}/{project}/_apis/test/Runs/{runId}/results?api-version=5.1
因此,您可以在管道中添加脚本任务以在其余 API 之上运行。见下例:
- powershell: |
$url = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/test/runs?buildIds=1417&buildDefIds=8&api-version=5.1"
$runs = Invoke-RestMethod -Uri $url -Headers @{authorization = "Bearer $(system.accesstoken)"} -ContentType "application/json" -Method get
$runId = $runs.value[-1].id
#get testCaseresultId
$resuilturl = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/test/Runs/$($runId)/results?api-version=5.1"
$results = Invoke-RestMethod -Uri $resuilturl -Headers @{authorization = "Bearer $(system.accesstoken)"} -ContentType "application/json" -Method get
#for example get first testCaseresultId
$testCaseResultId = $results.value[0].id
#create test result attachment.
$atturl = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/test/Runs/$($runId)/Results/$($testCaseResultId)/attachments?api-version=5.1-preview.1"
$body='{
"stream": "VXNlciB0ZXh0IGNvbnRlbnQgdG8gdXBsb2FkLg==",
"fileName": "$(System.DefaultWorkingDirectory)/screenshot-1.png",
"comment": "Test attachment upload",
"attachmentType": "GeneralAttachment"
}'
Invoke-RestMethod -Uri $atturl -Headers @{authorization = "Bearer $(system.accesstoken)"} -ContentType "application/json" -Method post -Body $body
【讨论】: