本文介绍了我们是否可以将屏幕截图作为附件添加到Azure管道中的测试结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用JUnit报告测试用例结果。据我所知,我们不能将屏幕截图或视频作为附件附加到Azure管道中由"发布测试结果"任务从JUnit格式生成的结果。
下面是我用于将屏幕截图和视频生成为项目而不是附加到测试结果报告的代码。
jobs:
- job: Cypress_e2e_tests
pool:
vmImage: 'windows-latest'
variables:
npm_config_cache: C:UsersVssAdministratorAppDataLocal
pm-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:UsersVssAdministratorAppDataLocalCypress'
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()
是否可以将这些项目附加到测试结果,而不是将这两个项目作为单独的部分保留?
如果我们可以从节点项目生成带有附件的测试结果(我们可以使用.Net项目可用的报告器附加文件,但我的工作项目完全基于该节点),这将是我的最佳解决方案。
推荐答案
对于此问题,答案是是。您可以在powershell任务中编写脚本,在脚本中调用Create Test Result Attachment睡觉接口。通过此睡觉接口,您可以将文件附加到测试结果上。
请求URL:
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"
}
下面是我的邮递员测试:
这篇关于我们是否可以将屏幕截图作为附件添加到Azure管道中的测试结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!