David Paquette

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:


  

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 /
    screenshot: 'only-on-failure',
    / 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