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

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

To show a screenshot beside a failed test in Allure, capture the browser state through your test framework and attach the resulting PNG to the Allure test result. The exact setup depends on the runner and Allure integration: some integrations capture automatically when configured, while others require a failure hook or a separate attachment call. A screenshot that was saved to disk is not necessarily attached to Allure.

How Allure failure screenshots work

Allure reports display attachments alongside the test result and, depending on the integration, can associate them with a test, step, or fixture. For supported media, the report provides a preview as well as a download link. The Allure Report documentation recommends capturing a screenshot when a graphical-interface test fails; attaching one at every step can help with longer scenarios, but it uses more storage.

Think of failure screenshots as two operations:

  1. Capture: ask the browser or test integration for an image, either as bytes or a file.
  2. Attach: pass those bytes or that file to the Allure integration, with a useful name and PNG media type.

Some integrations join these operations for you. Others need an explicit hook. A screenshot shows the visible state at one moment; it does not explain every preceding interaction or network delay. Traces, logs, page source, or video can provide different context.

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

Choose the setup for your integration

Stack Failure capture Allure attachment Important condition
Pytest + Selenium Use the Selenium debug hook to obtain the screenshot, or capture directly from the driver. Attach decoded PNG bytes with Allure, or attach an existing file. For a screenshot just captured, bytes avoid a possible empty-file race before the file is readable.
Pytest + Playwright Configure --screenshot only-on-failure to save screenshots after failures. Attach the saved PNG in a teardown hook, or attach screenshot bytes directly. Capture-to-disk and inclusion in Allure are separate. Playwright Pytest recreates its test-results directory on each run.
Allure Playwright Java allure.playwright.failure.screenshot=true is documented as enabled by default. The integration captures screenshots for registered pages. At least one page must be registered, explicitly or through the documented factory mechanism when AspectJ weaving is active.
Selenide + JUnit 5 Enable screenshots on the Allure Selenide listener. The listener attaches screenshots Selenide takes by default on failure. This listener configuration is specific to Selenide; do not assume it applies to plain Selenium.

These behaviors are integration-specific. Check the documentation for the exact versions of your runner and Allure adapter before copying configuration into a different stack.

Pytest with Selenium: attach the failure image

Attach a screenshot you capture in the test

When your test already has access to the WebDriver, attach its PNG bytes directly. This avoids having to coordinate a newly written file with the attachment step.

import allure
from allure_commons.types import AttachmentType

def test_checkout(driver):
    # ...perform the test...
    png = driver.get_screenshot_as_png()
    allure.attach(
        png,
        name="checkout-state",
        attachment_type=AttachmentType.PNG,
    )

This explicit example attaches at the point where it runs. To attach only after a failure, place capture and attachment in the failure-handling hook used by your Selenium/Pytest setup rather than calling it unconditionally in the test. Avoid attaching in a finally block without checking the outcome: that would also attach images for successful tests.

Use the Selenium capture-debug hook

The Allure Pytest/Selenium guide demonstrates a pytest_selenium_capture_debug hook. Selenium supplies debug entries; the hook locates the entry named Screenshot, decodes its base64 content, then calls Allure with PNG attachment type. The key shape is:

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.
import base64
import allure
from allure_commons.types import AttachmentType

def pytest_selenium_capture_debug(item, report, extra):
    for entry in extra:
        if entry.get("name") == "Screenshot":
            content = base64.b64decode(entry["content"])
            allure.attach(
                content,
                name=f"{item.name}-failure",
                attachment_type=AttachmentType.PNG,
            )

Use the hook signature expected by the installed Selenium Pytest plugin. It only attaches an image if that plugin provides the screenshot entry; a hook that runs without such an entry cannot create an image on its own. The bytes-based attachment is useful when the capture has just occurred and a disk file may not yet be available to read.

Attach a saved file instead

If another part of your test has already saved the PNG and the path is stable, Allure can attach that file:

allure.attach.file(
    "artifacts/checkout.png",
    name="checkout-state",
    attachment_type=AttachmentType.PNG,
)

Make sure the file exists before the call and is not empty. A file attachment is convenient for existing artifacts; for a just-captured Selenium screenshot, passing driver.get_screenshot_as_png() bytes is the safer route described in the Allure guide.

Pytest with Playwright: save first, then attach

For Playwright Pytest, the documented failure-only capture option is --screenshot only-on-failure. This tells Playwright Pytest to save a screenshot after a failed test, but it does not by itself mean the image is included as an Allure attachment. Use the Allure attachment call in the teardown path that handles the saved test artifact.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
pytest --screenshot only-on-failure

In your Allure teardown hook, locate the PNG produced for the failed test and attach it as a file. The exact artifact path depends on your project configuration and the Playwright Pytest version, so use the path supplied by that integration rather than assuming every project writes to the same location:

allure.attach.file(
    screenshot_path,
    name="failure-screenshot",
    attachment_type=AttachmentType.PNG,
)

Alternatively, take a screenshot through the Playwright page and attach the returned bytes directly:

png = await page.screenshot(full_page=True)
allure.attach(
    png,
    name="failure-screenshot",
    attachment_type=AttachmentType.PNG,
)

Use the async or sync form appropriate to your Playwright test. If the test-results directory is recreated on each run, move or publish artifacts separately when you need retention beyond that run; Allure attachments and the framework’s temporary artifact directory have different lifecycles.

Allure Playwright Java: check page registration

The Allure Playwright Java integration documents allure.playwright.failure.screenshot=true; failure screenshots are enabled by default. It captures each registered page when a test is failed or broken. If no page is registered, the default property alone is not enough to identify a page to capture.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
allure.playwright.failure.screenshot=true

Register pages explicitly, or use the documented factory mechanism when AspectJ weaving is active. The related property allure.playwright.failure.page-source=true enables capture of current HTML for registered pages; page source is a separate artifact and may expose content that is not apparent in the screenshot. Review what your report recipients can access before enabling it.

Selenide with JUnit 5: use the Allure listener

For Selenide with JUnit 5, the Allure guide demonstrates registering an AllureSelenide listener and enabling screenshots with .screenshots(true). The listener attaches screenshots Selenide takes by default on failure.

new AllureSelenide().screenshots(true)

The exact listener registration point depends on the test setup. This is Selenide behavior, not a general Selenium switch. For manual attachment in this stack, the guide also demonstrates an @Attachment method returning bytes or Allure.attachment; use that when you need to control the capture or attachment name yourself.

Make failure attachments useful and safe

  • Name by test or state. Prefer a stable name such as checkout-validation-error to an opaque timestamp alone.
  • Attach at the right level. A test-level image suits a final failure state; a step-level image can disambiguate a long workflow but multiplies artifact volume.
  • Choose the artifact deliberately. A screenshot answers what was visible. A Playwright trace can show DOM snapshots, network activity, console logs, and actions; it is richer, but not interchangeable with a still image.
  • Protect sensitive UI. Browser screenshots can expose account details, personal data, or tokens rendered on screen. Restrict report access and avoid capturing sensitive screens unnecessarily.
  • Plan retention. Determine whether your CI retains Allure results, framework artifacts, or both, and for how long. Do not assume a temporary test-results folder is a durable archive.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot missing or unusable screenshots

  • No attachment appears in Allure: confirm the capture ran, then verify that the Allure attachment call or integration listener ran too. For Playwright Pytest, the failure-only flag saves a file; a separate Allure attachment step is needed.
  • The Java integration captures nothing: check that the failing test has a registered page. Verify the failure screenshot property and, if relying on factory registration, that the documented AspectJ weaving setup is active.
  • The attachment is empty: for a fresh Selenium capture, pass PNG bytes directly rather than immediately reopening a file that may not yet be readable. For file-based attachment, check that the path exists and its size is nonzero before attaching.
  • The hook never runs: verify that the correct plugin/integration is installed and that the hook name and signature match its version. A Selenium debug hook also needs a screenshot entry in its supplied data.
  • The image disappears after a later run: the Playwright Pytest test-results directory is recreated on each run. Preserve required artifacts through your CI or other retention process.
  • The report has too many large artifacts: limit captures to failures or selected diagnostic steps. If interaction timing matters, consider failure-retained traces rather than taking screenshots at every step.

Or skip the browser setup

For a public URL that can be captured independently of the live test browser, ScreenshotNeo offers a one-request screenshot API and an MCP server for AI agents. This does not attach the current Selenium or Playwright browser session to Allure; use the framework-specific attachment method above when the failing state depends on that session.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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 API documentation for request options. Before capture, it accepts consent banners and removes 60+ known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, with response headers indicating the page verdict and billing status. Its MCP server includes take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients. The Free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000 shots.

Learn about ScreenshotNeo, or sign up free for 1,000 screenshots a month with no card.

Sources and version scope

The integration behaviors described here follow the official Allure documentation for Attachments, Pytest/Selenium, Pytest/Playwright, Allure Playwright Java, Allure Playwright, and Selenide/JUnit 5. Their APIs and defaults are integration-specific; check the documentation matching your installed versions before treating a snippet as drop-in configuration.

Frequently Asked Questions

Can Allure show a screenshot preview rather than only a file link?

Yes. Allure provides a preview for supported media types, including PNG images.

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

Should I attach a trace as well as a screenshot?

Only when the extra interaction, DOM, network, or console context is useful and your artifact-retention and privacy policies allow it.

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.