{"id":98,"date":"2024-02-15T16:28:33","date_gmt":"2024-02-15T16:28:33","guid":{"rendered":"https:\/\/rssfeedtelegrambot.bnaya.co.il\/index.php\/2024\/02\/15\/junit-attachments-support-for-publish-test-results\/"},"modified":"2024-03-17T18:34:32","modified_gmt":"2024-03-17T18:34:32","slug":"junit-attachments-support-for-publish-test-results","status":"publish","type":"post","link":"https:\/\/rssfeedtelegrambot.bnaya.co.il\/index.php\/2024\/02\/15\/junit-attachments-support-for-publish-test-results\/","title":{"rendered":"JUnit Attachments Support for Publish Test Results"},"content":{"rendered":"<p>We\u2019ve recently made some improvements to the <a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/devops\/pipelines\/tasks\/reference\/publish-test-results-v2\" target=\"_blank\" rel=\"noopener\">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\u2019t 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:<\/p>\n<p>&lt;testcase name=&#8221;my test case&#8221; classname=&#8221;example.spec.ts&#8221; time=&#8221;6.473&#8243;&gt;<br \/>\n  &lt;system-out&gt;<br \/>\n&lt;![CDATA[<br \/>\n[[ATTACHMENT|test-results\/example-has-title-chromium\/test-failed-1.png]]<br \/>\n[[ATTACHMENT|test-results\/example-has-title-chromium\/trace.zip]]<br \/>\n]]&gt;<br \/>\n  &lt;\/system-out&gt;<br \/>\n&lt;\/testcase&gt;<\/p>\n<p>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.\u00a0<\/p>\n<h2>Publishing Playwright JUnit Test Results<\/h2>\n<p>If you\u2019re using &gt;v1.3.9 of <a href=\"https:\/\/playwright.dev\/\" target=\"_blank\" rel=\"noopener\">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<p>reporter: [[&#8216;list&#8217;], [&#8216;junit&#8217;, {outputFile: &#8216;results.xml&#8217;}]],<br \/>\n  use: {<br \/>\n    \/* Save screenshots on failure &lt;em&gt;\/<br \/>\n    screenshot: &#8216;only-on-failure&#8217;,<br \/>\n    \/&lt;\/em&gt; Collect trace when retrying the failed test. See https:\/\/playwright.dev\/docs\/trace-viewer *\/<br \/>\n    trace: &#8216;retain-on-failure&#8217;,<br \/>\n  },<\/p>\n<p>In Azure Pipelines, use the PublishTestResults@2 task to publish the JUnit report file output from Playwright.<\/p>\n<p>steps:<br \/>\n&#8211; script: |<br \/>\n    npm install<br \/>\n  displayName: &#8216;npm install&#8217;<\/p>\n<p>&#8211; script: |<br \/>\n    npx playwright install<br \/>\n  displayName: &#8216;Playwright install&#8217;<\/p>\n<p>&#8211; script: |<br \/>\n    npx playwright test<br \/>\n  displayName: &#8216;Run Playwright tests&#8217;<\/p>\n<p>&#8211; task: PublishTestResults@2<br \/>\n  inputs:<br \/>\n    testResultsFormat: &#8216;JUnit&#8217;<br \/>\n    testResultsFiles: &#8216;results.xml&#8217;<br \/>\n  condition: always()<\/p>\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\"><\/a><\/p>\n<p>The post <a href=\"https:\/\/devblogs.microsoft.com\/devops\/junit-attachments-support-for-publish-test-results\/\">JUnit Attachments Support for Publish Test Results<\/a> appeared first on <a href=\"https:\/\/devblogs.microsoft.com\/devops\">Azure DevOps Blog<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>We\u2019ve recently made some improvements to the Publish Test Results task in Azure Pipelines. This task now supports file attachments [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":39,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[3],"tags":[],"class_list":["post-98","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-azure"],"_links":{"self":[{"href":"https:\/\/rssfeedtelegrambot.bnaya.co.il\/index.php\/wp-json\/wp\/v2\/posts\/98","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rssfeedtelegrambot.bnaya.co.il\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rssfeedtelegrambot.bnaya.co.il\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rssfeedtelegrambot.bnaya.co.il\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rssfeedtelegrambot.bnaya.co.il\/index.php\/wp-json\/wp\/v2\/comments?post=98"}],"version-history":[{"count":1,"href":"https:\/\/rssfeedtelegrambot.bnaya.co.il\/index.php\/wp-json\/wp\/v2\/posts\/98\/revisions"}],"predecessor-version":[{"id":263,"href":"https:\/\/rssfeedtelegrambot.bnaya.co.il\/index.php\/wp-json\/wp\/v2\/posts\/98\/revisions\/263"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rssfeedtelegrambot.bnaya.co.il\/index.php\/wp-json\/wp\/v2\/media\/39"}],"wp:attachment":[{"href":"https:\/\/rssfeedtelegrambot.bnaya.co.il\/index.php\/wp-json\/wp\/v2\/media?parent=98"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rssfeedtelegrambot.bnaya.co.il\/index.php\/wp-json\/wp\/v2\/categories?post=98"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rssfeedtelegrambot.bnaya.co.il\/index.php\/wp-json\/wp\/v2\/tags?post=98"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}