Reputation: 31
I have made some automated test (Testcafe) and put them together in one of my VS projects folder as shown here.
1.Script to run and take screenshots on failure:
script: testcafe chrome **/Tests/**/* -S -s takeOnFails=true --reporter spec,xunit:report.xml
displayName: Run tests and save screenshots
continueOnError: true
2.Script for publishing:
- task: PublishTestResults@2
displayName: Publish test results
continueOnError: true
inputs:
testResultsFiles: '**/report.xml'
searchFolder: $(System.DefaultWorkingDirectory)
testResultsFormat: 'JUnit'
publishRunAttachments: true
testRunTitle: "Task Results"
failTaskOnFailedTests: false
3.Script for copying files and build artifact:
- task: CopyFiles@2
inputs:
sourceFolder: '$(Build.SourcesDirectory)'
contents: '**/?(*.png)'
targetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: Saved failure screenshots
Is there any way to add screenshots as attachment on test run created at step 2 like this using Yaml?
Currently screenshots can be seen at artifact result from step 3 but I want them to be attached to test run.
Upvotes: 3
Views: 4311
Reputation: 838
Azure DevOps does not support attachments (other than the test result file) if you use the JUnit or xUnit report format. See Capture Screenshots in the Azure docs.
To upload screenshots as attachments with the Publish Test Results task, you need to generate an NUnit 3.0 report. You may want to take a look at this community-developed TestCafe reporter for NUnit 3.0: https://github.com/NickLargen/testcafe-reporter-nunit3
According to the reporter's documentation, it can include videos and screenshots as test case attachments. Please note that since this plugin is supported by the community, we cannot promise that it will work as expected in all cases.
Upvotes: 2