February 15th, 2024

JUnit Attachments Support for Publish Test Results

David Paquette
Senior Software Engineer

We’ve recently made some improvements to the Publish Test Results task in Azure Pipelines. This task now supports file attachments when publishing test results from a JUnit report.

JUnit Attachments Report Format

The JUnit XML report format doesn’t officially have support for file attachments but there is a common convention of including attachments in the element of each test case. Attachments are specified in the format [[ATTACHMENT|/path/to/file.ext]]. For example:

<testcase name="my test case" classname="example.spec.ts" time="6.473">
  <system-out>
<![CDATA[
[[ATTACHMENT|test-results/example-has-title-chromium/test-failed-1.png]]
[[ATTACHMENT|test-results/example-has-title-chromium/trace.zip]]
]]>
  </system-out>
</testcase>

The Publish Test Results task will automatically look for any attachments listed in the element, upload those attachments to Azure DevOps, and associate them with the test results. Attachments paths can be either absolute or relative to the location of the JUnit report file. 

Publishing Playwright JUnit Test Results

If you’re using >v1.3.9 of Playwright, screenshots, recordings and trace files can automatically be associated directly with Test Results in Azure Pipelines.

In playwright.config.ts, configure the JUnit reporter and configure Playwright to save screenshots and trace files whenever a test fails:

reporter: [['list'], ['junit', {outputFile: 'results.xml'}]],
  use: {
    /* Save screenshots on failure <em>/
    screenshot: 'only-on-failure',
    /</em> Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
    trace: 'retain-on-failure',
  },

In Azure Pipelines, use the PublishTestResults@2 task to publish the JUnit report file output from Playwright.

steps:
- script: |
    npm install
  displayName: 'npm install'

- script: |
    npx playwright install
  displayName: 'Playwright install'

- script: |
    npx playwright test
  displayName: 'Run Playwright tests'

- task: PublishTestResults@2
  inputs:
    testResultsFormat: 'JUnit'
    testResultsFiles: 'results.xml'
  condition: always()
   

To review attachments, navigate to the test results for your pipeline run, click on a failed test, then click on the Attachments tab. You can preview/download images and trace files for further investigation.

Screenshot showing Playwright screenshot and trace file attached to test case results in Azure Pipelines

Author

David Paquette
Senior Software Engineer

2 comments

Discussion is closed. Login to edit/delete existing comments.

  • Chandrakant Singh

    Hi David, I was trying to implement this to see the screenshot/video/trace generated by Playwright in the Tests>Attachments in ADO. I can see the Standard_Console_Output with below code and I have validated that these paths are correct by uploading the "test-results" folder as a pipeline artifact. However, I cannot see the image/video/trace files on the attachment tab.

    Do you know what is missing to make this work? Are there any permissions that needs to be reviewed?

    <code>

    Thanks,Read more

    • David PaquetteMicrosoft employee Author

      We are receiving reports of similar issues from customers and are currently investigating. Can you confirm what agents you are running (e.g. ubuntu-latest, windows-latest)?