{"id":67933,"date":"2024-02-15T08:28:33","date_gmt":"2024-02-15T16:28:33","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/devops\/?p=67933"},"modified":"2024-02-15T08:28:33","modified_gmt":"2024-02-15T16:28:33","slug":"junit-attachments-support-for-publish-test-results","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/devops\/junit-attachments-support-for-publish-test-results\/","title":{"rendered":"JUnit Attachments Support for Publish Test Results"},"content":{"rendered":"<p>We&#8217;ve recently made some improvements to the <a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/devops\/pipelines\/tasks\/reference\/publish-test-results-v2\" rel=\"noopener\" target=\"_blank\">Publish Test Results task<\/a> in Azure Pipelines. This task now supports file attachments when publishing test results from a JUnit report.<\/p>\n<h2>JUnit Attachments Report Format<\/h2>\n<p>The JUnit XML report format doesn&#8217;t officially have support for file attachments but there is a common convention of including attachments in the <system-out> element of each test case. Attachments are specified in the format <code>[[ATTACHMENT|\/path\/to\/file.ext]]<\/code>. For example:<\/system-out><\/p>\n<pre class=\"prettyprint language-xml\"><code class=\"language-xml\">&#60;testcase name=\"my test case\" classname=\"example.spec.ts\" time=\"6.473\"&#62;\n  &#60;system-out&#62;\n&#60;![CDATA[\n[[ATTACHMENT|test-results\/example-has-title-chromium\/test-failed-1.png]]\n[[ATTACHMENT|test-results\/example-has-title-chromium\/trace.zip]]\n]]&#62;\n  &#60;\/system-out&#62;\n&#60;\/testcase&#62;<\/code><\/pre>\n<p>The Publish Test Results task will automatically look for any attachments listed in the <system-out> 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.\u00a0<\/system-out><\/p>\n<h2>Publishing Playwright JUnit Test Results<\/h2>\n<p>If you&#8217;re using >v1.3.9 of <a href=\"https:\/\/playwright.dev\/\" rel=\"noopener\" target=\"_blank\">Playwright<\/a>, screenshots, recordings and trace files can automatically be associated directly with Test Results in Azure Pipelines.<\/p>\n<p>In playwright.config.ts, configure the JUnit reporter and configure Playwright to save screenshots and trace files whenever a test fails:<\/p>\n<pre class=\"prettyprint language-json\"><code class=\"language-json\">reporter: [['list'], ['junit', {outputFile: 'results.xml'}]],\n  use: {\n    \/* Save screenshots on failure &#60;em&#62;\/\n    screenshot: 'only-on-failure',\n    \/&#60;\/em&#62; Collect trace when retrying the failed test. See https:\/\/playwright.dev\/docs\/trace-viewer *\/\n    trace: 'retain-on-failure',\n  },<\/code><\/pre>\n<p>In Azure Pipelines, use the PublishTestResults@2 task to publish the JUnit report file output from Playwright.<\/p>\n<pre class=\"prettyprint undefined\"><code class=\"undefined\">steps:\n- script: |\n    npm install\n  displayName: 'npm install'\n\n- script: |\n    npx playwright install\n  displayName: 'Playwright install'\n\n- script: |\n    npx playwright test\n  displayName: 'Run Playwright tests'\n\n- task: PublishTestResults@2\n  inputs:\n    testResultsFormat: 'JUnit'\n    testResultsFiles: 'results.xml'\n  condition: always()\n   <\/code><\/pre>\n<p>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.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2023\/11\/Playwright-JUnit-Attachments-Azure-Pipelines.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2023\/11\/Playwright-JUnit-Attachments-Azure-Pipelines-small.png\" alt=\"Screenshot showing Playwright screenshot and trace file attached to test case results in Azure Pipelines\" class=\"aligncenter size-full wp-image-67934\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>We&#8217;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&#8217;t officially have support for file attachments but there is a common convention of including attachments in the [&hellip;]<\/p>\n","protected":false},"author":134179,"featured_media":66985,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[224,226,229,1,252],"tags":[],"class_list":["post-67933","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-azure","category-ci","category-community","category-devops","category-testing"],"acf":[],"blog_post_summary":"<p>We&#8217;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&#8217;t officially have support for file attachments but there is a common convention of including attachments in the [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/67933","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/users\/134179"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/comments?post=67933"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/67933\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media\/66985"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media?parent=67933"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/categories?post=67933"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/tags?post=67933"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}