gpt4 book ai didi

node.js - 我们可以将屏幕截图作为附件添加到 Azure 管道中的测试结果吗

转载 作者:行者123 更新时间:2023-12-05 05:06:59 27 4
gpt4 key购买 nike

我使用 JUnit 报告测试用例结果。根据我的理解,我们无法将屏幕截图或视频作为附件附加到 Azure 管道中的 JUnit 格式的“发布测试结果”任务生成的结果。

下面是我用于生成屏幕截图和视频作为工件而不是附加到测试结果报告的代码。

   jobs:
- job: Cypress_e2e_tests
pool:
vmImage: 'windows-latest'
variables:
npm_config_cache: C:\Users\VssAdministrator\AppData\Local\npm-cache


steps:
- task: NodeTool@0
inputs:
versionSpec: '10.x'
- task: CacheBeta@1
inputs:
key: npm | $(Agent.OS) | package-lock.json
path: $(npm_config_cache)
restoreKeys: npm | $(Agent.OS) | package-lock.json
displayName: Cache NPM packages

- task: CacheBeta@1
inputs:
key: 'cypress | $(Agent.OS) | package-lock.json'
path: 'C:\Users\VssAdministrator\AppData\Local\Cypress'
restoreKeys: 'cypress | $(Agent.OS) | package-lock.json'
displayName: Cache cypress binary

- script: npm cache verify
displayName: 'NPM verify'

- script: npm ci
displayName: 'Install NPM dependencies'

- script: npm run cy:verify
displayName: 'Cypress verify'

- script: |
npx cypress run --browser chrome
displayName: 'Run Cypress tests'
workingDirectory: $(System.DefaultWorkingDirectory)


- task: PublishPipelineArtifact@0
displayName: 'Publish Screenshots (Cypress)'
condition: failed()
inputs:
artifactName: 'screenshots'
targetPath: '$(Build.SourcesDirectory)/cypress/screenshots'

- task: PublishPipelineArtifact@0
displayName: 'Publish Videos (Cypress)'
condition: failed()
inputs:
artifactName: 'videos'
targetPath: '$(Build.SourcesDirectory)/cypress/videos'


- task: PublishTestResults@2
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '*.xml'
failTaskOnFailedTests: true
testRunTitle: 'Cypress Test Results'
publishRunAttachments: true
condition: succeededOrFailed()

有什么方法可以将这些工件附加到测试结果中,而不是将这两个部分保留为单独的部分吗?

如果我们可以从 Node 项目生成带有附件的测试结果(我们可以使用可用于 .Net 项目的报告程序附加文件,但我的工作项目完全基于 Node ),这对我来说将是最好的解决方案。

最佳答案

Can we add screenshots as an attachment to the test result in azure pipeline

对于这个问题,答案是。您可以在 PowerShell 任务中编写脚本并调用 Create Test Result Attachment在其中休息 api。通过此 rest api,您可以将文件附加到测试结果。

请求地址:

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

示例请求正文:

{
"stream": "VXNlciB0ZXh0IGNvbnRlbnQgdG8gdXBsb2FkLg==",
"fileName": "Notifications.png",
"comment": "Test attachment upload",
"attachmentType": "GeneralAttachment"
}

下面是我在 postman 中的测试:

enter image description here

enter image description here

关于node.js - 我们可以将屏幕截图作为附件添加到 Azure 管道中的测试结果吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59511868/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com