【问题标题】:Add screenshots to XUNIT test results from Robot framework to Azure Pipelines test tab将屏幕截图添加到从机器人框架到 Azure Pipelines 测试选项卡的 XUNIT 测试结果
【发布时间】:2020-10-19 18:09:28
【问题描述】:

是否有一种简单的方法可以将 Robot Framework 生成的 XUNIT 样式测试结果的屏幕截图链接起来,并通过 Azure Pipelines 的发布测试结果任务将它们加载到测试选项卡中?

与他们处理 VSTS 结果文件的方式类似。

提前致谢。

【问题讨论】:

    标签: python automated-tests robotframework azure-pipelines xunit


    【解决方案1】:

    恐怕上面没有简单的方法来实现。

    作为一种解决方法,您可以使用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
    

    【讨论】:

    • 嗨,你能告诉我我应该在我的代码中提供什么路径来保存屏幕截图吗?就像我给这个字符串路径 = Directory.GetCurrentDirectory() + "\\" + TestCaseName + ".png";
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-19
    • 2021-02-04
    • 2013-11-28
    • 1970-01-01
    • 1970-01-01
    • 2019-11-09
    相关资源
    最近更新 更多