Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To show screenshots alongside failed JUnit tests, capture the image in your test or browser automation code, then attach it to the test result in a reporting system. JUnit-compatible XML contains test results; it does not itself capture screenshots or embed them. For a Jenkins-hosted report, publish the XML with the Jenkins JUnit plugin and configure the JUnit Attachments plugin for images. For a rendered HTML report, Maven Surefire Report can turn Surefire XML into HTML, while Allure can associate attachments with test results and show supported images.

“Embedded” can mean an inline image preview in a CI report or an image encoded inside a standalone HTML file. The official reporting documentation describes attachments and previews, not a universal command that produces a self-contained HTML file. Choose the workflow that matches the report your team needs.

Choose the report workflow first

JUnit test execution, screenshot capture, and report rendering are separate jobs. A test framework or browser driver must take the screenshot when a test fails. A reporting integration must associate the resulting file with the failed test. Finally, a renderer or CI system must display the test result and attachment.

What you need Practical route What it provides
A CI-hosted test report with inline image attachments Jenkins JUnit plugin plus Jenkins JUnit Attachments plugin Jenkins test results and image attachments in its test UI; attachment handling is configured separately from XML publishing.
A generated HTML rendering of Maven Surefire results Maven Surefire Report Plugin An HTML report rendered from Surefire XML. Its documentation does not establish screenshot embedding.
A richer report with per-test or per-step attachments and image previews Allure with a compatible framework integration Attachments associated with results, steps, or fixtures, with previews for supported media types.
XML output from JUnit Platform JUnit Platform reporting listener Open Test Reporting XML or legacy XML for downstream tools; not screenshot capture or embedding.

For Jenkins, use the attachment plugin when the priority is inline screenshots in the CI test UI. Use Surefire Report when you specifically need an HTML rendering of Maven test results, and pair it with an attachment-capable system if screenshots must appear beside individual tests. Consider Allure when its framework integration fits your stack and you want attachments associated with test steps or fixtures.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Jenkins: publish XML and attach screenshots

Jenkins’s JUnit plugin consumes JUnit-format XML and provides a test UI and history. Its documentation accepts report paths using Ant glob syntax and cautions that the pattern should select report XML rather than other files. The JUnit Attachments plugin is a separate feature: its documented settings enable attachments under “Additional test report features” by selecting “Publish test attachments.”

1. Capture the screenshot when the test fails

Take the screenshot in the test framework or browser automation code, at the point where the failure can still be inspected. Save it to a predictable location within the workspace. The reporting plugins do not take the screenshot for you; screenshot APIs vary by framework and driver.

For example, a browser test can write a failure screenshot under a workspace path such as target/surefire-reports/com.example.CheckoutTest/failure.png. Use your own framework’s screenshot API and ensure the file is written before the test process or CI workspace is cleaned up.

2. Associate the file with the test result

The Jenkins JUnit Attachments plugin documents two approaches:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Class-named attachment directory: put attachments in a directory named for the test class beside the XML report. The plugin example places files in target/surefire-reports/foo.bar.MyTest/ beside TEST-foo.bar.MyTest.xml. Adapt the package and class directory to the test whose attachment you want shown.
  • Attachment marker: print a marker on its own line to stdout or stderr, using the absolute path to the file: [[ATTACHMENT|/absolute/path/to/some/file]]. Ensure the path exists when Jenkins processes the test output.

Use the method supported by your plugin configuration and test-runner output. Keep attachment names clear and avoid deleting the files before Jenkins archives them.

3. Publish only the test XML, including after failures

In a Pipeline, publish results in a post block with an always condition so the reporting step runs when tests fail:

post {
  always {
    junit 'build/reports/**/*.xml'
  }
}

Change the glob to the location where your build actually writes its test XML. Verify that it matches report files only, not arbitrary XML or attachment content. Jenkins documents that a pipeline with failed tests is marked UNSTABLE by the JUnit result step; that is different from the build state FAILED.

Install and configure the JUnit Attachments plugin as well as the JUnit publisher if inline attachments are required. Plugin listings and compatibility change: the listing consulted on September 30, 2026 reported version 378.vc1dc9200b_6b_a_ and a Jenkins 2.504.3 requirement. Check the current plugin listing and your controller compatibility before installing; do not assume those listing details remain current.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Generate an HTML report from Maven Surefire XML

The Maven Surefire Report Plugin parses TEST-*.xml files under ${basedir}/target/surefire-reports and renders an HTML report. This supplies the HTML presentation of test results, but the cited plugin documentation does not describe embedding screenshots into that HTML.

That distinction matters: generating an HTML report from XML does not automatically associate arbitrary image files with a particular failed test. If inline screenshots are essential, choose an attachment-capable reporting workflow such as Jenkins attachments or Allure, or confirm that the specific renderer and integration you use support the exact output you want.

JUnit Platform XML is an input format, not a screenshot report

JUnit Platform’s junit-platform-reporting provides Open Test Reporting XML and legacy XML. The legacy format is described as compatible with the de facto JUnit 4 report format popularized by Ant. The documented output directory can be configured with junit.platform.reporting.output.dir; its default is build when a Gradle build is detected, target for a Maven POM, and the current working directory otherwise. The Open Test Reporting listener is controlled by junit.platform.reporting.open.xml.enabled=true|false.

These settings determine XML reporting, not image capture or screenshot embedding. Generate the XML your downstream renderer accepts, then use that renderer’s attachment mechanism to connect image files to results.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Allure for attachments and image previews

Allure supports attaching files to a whole test result or, depending on the integration, to a test step or fixture. Its report offers a download link and previews for supported media types, including image/bmp, image/gif, image/jpeg, image/png, image/svg+xml, image/tiff, and image/*.

Screenshot capture and automatic attachment depend on the chosen framework integration. Confirm whether your integration captures screenshots automatically or whether your test code must capture and attach them explicitly. A screenshot file that exists on disk but is never attached to the relevant result will not become a per-test preview simply because the report is generated.

Inline preview versus a self-contained HTML file

Before implementation, decide what “embedded” means for your use case:

  • Inline in a CI report: Jenkins attachment handling or Allure previews can display images in the report interface, subject to configuration and integration.
  • Downloadable attachment: the report can link to an image file without encoding it into the HTML document.
  • Self-contained HTML: the image data must be included in the HTML itself, commonly as data URLs. The cited Jenkins, Surefire Report, JUnit Platform, and Allure documentation does not establish that their standard outputs create one universally self-contained HTML artifact.

If you need a single file that works offline or can be emailed without a companion attachments directory, verify that the selected reporting tool explicitly supports inlining image data. Do not treat an inline preview in a hosted report as proof that the exported HTML is self-contained.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Or skip the browser setup

If what you need is a screenshot of a web page involved in a failed test, you can capture it through a screenshot API instead of setting up a browser capture workflow. ScreenshotNeo is a website screenshot API and MCP server; it does not replace JUnit result publishing or automatically attach an image to a test result. Your test or reporting code still needs to associate the returned image with the failure.

For example, save a screenshot of the URL your test was checking:

curl -G "https://api.screenshotneo.com/v1/shot" 
  -d access_key=YOUR_API_KEY 
  --data-urlencode url=https://stripe.com 
  -o shot.webp

See the ScreenshotNeo documentation for request options. Cookie banners, popups, and chat widgets are removed before the shot; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots. The Free plan includes 1,000 screenshots a month with no card, and paid plans start at $5 for 3,000. Sign up for ScreenshotNeo free.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting common reporting failures

Jenkins shows no tests

  • Check that test execution produced XML at the path your junit step searches.
  • Adjust the Ant glob to the actual report directory and ensure it selects XML report files only.
  • Publish results in post { always { ... } } so failed tests do not bypass publication.

The test appears, but its screenshot does not

  • Confirm the image was actually written and remains in the workspace when Jenkins processes results.
  • For the directory method, verify the attachment directory is beside the XML and named for the test class, including its package as expected by the plugin convention.
  • For the marker method, print [[ATTACHMENT|/absolute/path/to/some/file]] on its own output line and check that the absolute path resolves on the Jenkins agent.
  • Verify that “Publish test attachments” is enabled under “Additional test report features.”

The HTML report contains test data but no image

Surefire Report renders test XML; its documentation does not claim screenshot embedding. Add a reporting integration that supports attachments, and make sure your test code creates and associates the screenshot rather than only saving it somewhere in the build directory.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The build is unstable rather than failed

Jenkins documents that the JUnit result step marks a pipeline with failing tests UNSTABLE. This is expected result reporting behavior and is distinct from the pipeline being FAILED; inspect the published test results and your pipeline’s status policy separately.

A plugin installation is incompatible

Jenkins plugin versions and minimum controller requirements can change. Check the current plugin listing against your Jenkins version before installation, and use a version compatible with the controller rather than relying on a previously observed version number.

FAQ

Does JUnit XML contain screenshot images?

No. In this workflow XML carries test-result data. Image capture and attachment are separate capabilities supplied by test code and reporting integrations.

Can a screenshot be attached to a test step instead of the whole test?

Allure documents result-, step-, and fixture-level attachments, with exact behavior depending on the framework integration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Will Jenkins or Allure always produce one portable HTML file?

Not established by the cited documentation. Attachment previews in a hosted report do not necessarily mean image data is embedded in a standalone exported HTML file.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.