Azure DevOps运行结果步骤并运行摘要详细信息附件API

发布于 2025-02-12 04:18:21 字数 672 浏览 0 评论 0 原文

我正在尝试获取测试运行结果步骤和测试运行结果摘要详细信息的附件,但无法找到与该API有关的任何API 我正在附加矩形1下方的图像是测试运行结果步骤的刺激,而Rectangele 2是测试运行结果的附件摘要摘要

If anyone have any knowledge about these perticular apis please let me know.

我已经检查了 azure api文档,但如果我错过了特定的API请让我知道。 谢谢

I am trying to fetch the attachments of the Test Run Result steps and Test Run Result Summary Details but unable to find any API related to that
I am attaching the Image below Rectangle 1 is the attchments for Test Run Result Steps and Rectangele 2 is the attachments for Test Run Result Summary Detais
enter image description here

If anyone have any knowledge about these perticular apis please let me know.

I have checked the AZURE API Documentation but couldn't find the specific API if I have missied something please let me know.
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薄暮涼年 2025-02-19 04:18:22

通过调用获取测试结果附件 REST API,我们可以获取附件的所有ID:

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

此后,如果您想获得附件,则可以调用附件 - 获取测试结果附件zip 与特定附件ID REST API。

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

请注意,REST API 附件 - 获取测试结果附件zip 将显示附件的上下文,而不是直接下载附件。如果要下载附件,则可以编写脚本以将其保存到本地目录。以下供您参考的powerShell脚本:

$AttachmentsOutfile = "D:\Test\HellWorld.java"

$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

更新:

,但是获取测试结果附件 REST API只能从测试运行UI中获取附件(通过单击附加附件) 添加附件按钮)。

要获取测试运行结果步骤和测试结果摘要的附件,我们可以调用结果 - get 带有参数 defoce> detail stoinclude = iterations 添加添加:

GET https://dev.azure.com/{organization}/{project}/_apis/test/Runs/{runId}/results/{testCaseResultId}?detailsToInclude=iterations&api-version=6.0

“在此处输入图像描述”

之后,我们可以通过其ID下载附件。以下powershell脚本供您参考以在循环中下载它们:

Param(
   [string]$orgurl = "https://dev.azure.com/{org}",
   [string]$project = "Test0924",
   [string]$downloadlocation = "C:\temp\1025\",
   [string]$TestRunId = "1000294",
   [string]$ResultId = "100000",
   [string]$user = "",
   [string]$token = "PAT"
)
# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))

#List test result and test step attachments: 
$testresultUrl = "$orgurl/$project/_apis/test/Runs/$TestRunId/Results/$($ResultId)?detailsToInclude=iterations&api-version=6.0" 
$attachments = (Invoke-RestMethod -Uri $testresultUrl -Method Get -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}).iterationDetails.attachments

ForEach ($attachment in $attachments) {
#Get test result and step attachments:
$attachmentid = $attachment.id
$attachmentname = $attachment.name
$attachmenturl = "$orgurl/$project/_apis/test/Runs/$TestRunId/Results/$ResultId/attachments/$($attachmentid)?api-version=6.0"
Invoke-RestMethod -Uri $attachmenturl -Method Get -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -OutFile $downloadlocation\$attachmentname
}

By calling the Get Test Result Attachments REST API, we can get all the IDs of the attachments:

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

After that, if you want to get the attachments you can call Attachments - Get Test Result Attachment Zip REST API with the specific Attachment ID.

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

Please note that the REST API Attachments - Get Test Result Attachment Zip will display the context of the attachments instead of download the attachments directly. If you want to download the attachments, you can write a script to save them to a local directory. The following PowerShell script for your reference:

$AttachmentsOutfile = "D:\Test\HellWorld.java"

$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

UPDATE:

However the Get Test Result Attachments REST API can only get the attachments attached from the test run UI (attached by clicking the Add attachment button).

To get the attachments of the Test Run Result steps and Test Run Result Summary, we can call Results - Get REST API with parameter detailsToInclude=iterations added:

GET https://dev.azure.com/{organization}/{project}/_apis/test/Runs/{runId}/results/{testCaseResultId}?detailsToInclude=iterations&api-version=6.0

enter image description here

enter image description here

After that we can download the attachments by their ID. The following PowerShell script for your reference to download them in a loop:

Param(
   [string]$orgurl = "https://dev.azure.com/{org}",
   [string]$project = "Test0924",
   [string]$downloadlocation = "C:\temp\1025\",
   [string]$TestRunId = "1000294",
   [string]$ResultId = "100000",
   [string]$user = "",
   [string]$token = "PAT"
)
# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))

#List test result and test step attachments: 
$testresultUrl = "$orgurl/$project/_apis/test/Runs/$TestRunId/Results/$($ResultId)?detailsToInclude=iterations&api-version=6.0" 
$attachments = (Invoke-RestMethod -Uri $testresultUrl -Method Get -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}).iterationDetails.attachments

ForEach ($attachment in $attachments) {
#Get test result and step attachments:
$attachmentid = $attachment.id
$attachmentname = $attachment.name
$attachmenturl = "$orgurl/$project/_apis/test/Runs/$TestRunId/Results/$ResultId/attachments/$($attachmentid)?api-version=6.0"
Invoke-RestMethod -Uri $attachmenturl -Method Get -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -OutFile $downloadlocation\$attachmentname
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文