【问题标题】:How to attach screenshots at Pytest JUNIT xml to appear on Azure DevOps?如何在 Pytest JUNIT xml 中附加屏幕截图以显示在 Azure DevOps 上?
【发布时间】:2021-03-01 17:21:05
【问题描述】:

如何使用 Pytest 在 JUNIT xml 中自动添加屏幕截图?我希望将执行测试过程中的截图附在报告中,但是这部分的Pytest文档不是很清楚。

另外,Azure DevOps documentation 表示它可以自动将所有生成的文件作为附件上传。这是否取代了手动附加文件的需要?它如何将文件 A 与测试 X 附加在一起?

提前致谢!

【问题讨论】:

    标签: selenium junit azure-devops pytest azure-pipelines


    【解决方案1】:

    我希望在执行测试期间截取的屏幕截图是 附在报告中

    您可以尝试调用Create Test Result Attachmentrest api 将屏幕截图附加到测试附件选项卡。

    powershell 任务中的示例脚本:

    $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
    

    这个ticket给出了详细的指南,你可以参考它。

    另外,你可以直接尝试使用扩展Publish test result screenshot中的Publish screenshots for test failure任务。

    此扩展提供了一个构建任务以集成到您的持续集成管道中。此任务会将屏幕截图上传到来自 Visual Studio 测试 (TRX) 以外的来源(例如 jUnit)的测试结果报告。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多