如何在 Azure DevOps 中下载测试用例的测试步骤附件

How Do I Download Test Step Attachments for Test Cases in Azure DevOps

我正在尝试通过 API 使用 GET https://dev.azure.com/{organization}/{project}/_apis/test/Runs/{runId}/Results/{testCaseResultId}/attachments/{attachmentId}?api-version=6.0-preview.1 调用下载测试用例的所有测试步骤附件。

我的通话有效,但我在文件中的什么位置可以找到附件?

How Do I Download Test Step Attachments for Test Cases in Azure DevOps

那是因为 REST API Attachments - Get Test Result Attachment Zip 将显示附件的上下文,而不是直接下载附件。

要解决此问题,我们可以通过以下脚本将附件保存到文件中:

$AttachmentsOutfile = "D:\Testcase\AttachmentsOutfile.trx"

$connectionToken="You PAT Here"

$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::  
ASCII.GetBytes(":$($connectionToken)"))

$AuditLogURL = "https://dev.azure.com/{organization}/{project}/_apis/test/Runs/{runId}/Results/{testCaseResultId}/attachments/{attachmentId}?api-version=6.0-preview.1" 

$AuditInfo = Invoke-RestMethod -Uri $AuditLogURL -Headers @{authorization = "Basic $base64AuthInfo"} -Method Get –OutFile $AttachmentsOutfile

测试结果: