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

Capture the image with Playwright, then attach its bytes (or a copied file) with an image content type. For a whole-test attachment, call testInfo.attach(); for an attachment under a named action, call step.attach() inside test.step(). Allure’s JavaScript/TypeScript integration also accepts allure.attachment() and allure.attachmentPath(). The examples below show each supported placement and how to verify the generated report.

Prerequisites and the attachment model

The examples assume a Playwright Test project using JavaScript or TypeScript and an Allure Playwright reporter/integration. Pin compatible package versions in your project and verify the rendered report locally; the available documentation does not define one compatibility matrix for every Playwright, Allure Playwright and Node.js release.

A screenshot is not automatically a useful Allure attachment merely because it exists on disk. Your test must pass either the image bytes or a path to an attachment API, and the content type must identify the image. Playwright’s attachment APIs accept either body or path, never both.

Attach a screenshot to the test with Playwright Test

This is the simplest deliberate attachment. The screenshot is captured in memory and associated with the current test result.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
import { test } from '@playwright/test';

test('authentication page', async ({ page }, testInfo) => {
  await page.goto('https://example.com/login');

  const screenshot = await page.screenshot();
  await testInfo.attach('Login page', {
    body: screenshot,
    contentType: 'image/png',
  });
});

page.screenshot() returns a Buffer by default. Because the image is PNG, the attachment uses image/png. Give the attachment a descriptive name: it becomes the label readers see in the report.

Attach an existing image file

If another part of your test already wrote the image, provide a path instead of a Buffer and use the matching media type.

import { test } from '@playwright/test';
import path from 'node:path';

test('saved screenshot', async ({ page }, testInfo) => {
  await page.goto('https://example.com/login');
  const file = path.join(testInfo.outputDir, 'login.png');
  await page.screenshot({ path: file });

  await testInfo.attach('Login page (file)', {
    path: file,
    contentType: 'image/png',
  });
});

Await the attachment call. Playwright copies an attached file to a reporter-accessible location, so a temporary source file can be removed after the call resolves.

Put the screenshot under a named test step

Use a step attachment when the image explains one action or assertion rather than the test as a whole.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
import { test } from '@playwright/test';

test('authentication page', async ({ page }) => {
  await page.goto('https://example.com/login');

  await test.step('inspect login page', async step => {
    const screenshot = await page.screenshot();
    await step.attach('Login page', {
      body: screenshot,
      contentType: 'image/png',
    });
  });
});

testInfo.attach() places the item at test level; step.attach() attributes it to that step. The TestStepInfo.attach API was added in Playwright v1.51. If your installed Playwright is older, use a test-level attachment or upgrade after checking your project’s release policy.

Use Allure’s attachment API directly

The Allure JavaScript/TypeScript integration supports the same screenshot bytes through allure-js-commons. This is useful when you want to use Allure’s attachment calls consistently across test frameworks or helper code.

import { test } from '@playwright/test';
import * as allure from 'allure-js-commons';
import { ContentType } from 'allure-js-commons';

test('authentication page', async ({ page }) => {
  await page.goto('https://example.com/login');

  const screenshot = await page.screenshot();
  await allure.attachment('Login page', screenshot, ContentType.PNG);
});

For a file on disk, use Allure’s path-oriented method:

import { test } from '@playwright/test';
import * as allure from 'allure-js-commons';
import path from 'node:path';

test('authentication page', async ({ page }, testInfo) => {
  await page.goto('https://example.com/login');
  const file = path.join(testInfo.outputDir, 'login.png');
  await page.screenshot({ path: file });
  await allure.attachmentPath('Login page', file, {
    contentType: 'image/png',
  });
});

Choose one attachment route for a given image unless you intentionally want two copies. Playwright-native calls make placement in the Playwright result explicit; Allure calls are convenient in shared Allure helpers.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Capture screenshots automatically only when a test fails

For diagnostic evidence rather than a named checkpoint, configure Playwright Test:

import { defineConfig } from '@playwright/test';

export default defineConfig({
  use: {
    screenshot: 'only-on-failure',
  },
});

The documented values are off, on and only-on-failure. Generated screenshots and other artifacts normally go to the test output directory (typically test-results). The runner controls when the files are created; the reporter consumes the resulting attachments. Run a failing test and inspect your generated Allure report with the exact Playwright and Allure integration versions used in your project.

Which capture policy should you use?

Need Recommended policy Why
A checkpoint visible in every report Manual page.screenshot() plus attach() You control timing, name and placement.
Evidence tied to one action step.attach() inside test.step() The image appears under that named step.
Debugging failures with minimal artifacts screenshot: 'only-on-failure' Playwright captures only failed tests.
Every test, regardless of result screenshot: 'on' or explicit capture Useful for visual audit, but increases artifact volume.

Content types, formats and timing

  • Use image/png for the default PNG Buffer.
  • Use the corresponding image media type for JPEG screenshots, such as image/jpeg.
  • Capture after the page reaches the state you want to document. Wait for a locator, an assertion, or an application-specific readiness condition before calling screenshot().
  • Attach after capture and await the operation. Do not delete a source file until the awaited attachment call has completed.
  • Allure’s attachment viewer can preview supported image media. Correct typing is what lets the report recognize the file as an image rather than an unclassified binary.

Reliable patterns for real test suites

Capture after a meaningful assertion

import { test, expect } from '@playwright/test';

test('signed-in dashboard', async ({ page }, testInfo) => {
  await page.goto('https://example.com/login');
  await page.getByLabel('Email').fill('user@example.com');
  await page.getByLabel('Password').fill('secret');
  await page.getByRole('button', { name: 'Sign in' }).click();

  await expect(page.getByRole('heading', { name: 'Dashboard' })).toBeVisible();
  const image = await page.screenshot({ fullPage: true });
  await testInfo.attach('Dashboard after sign-in', {
    body: image,
    contentType: 'image/png',
  });
});

Taking the image after the visibility assertion avoids attaching an intermediate loading state. For very long pages, fullPage: true can create a large artifact; use a locator screenshot when only one component matters.

Keep failure evidence in a hook

If you need custom naming or a specific page state, capture in a test or fixture hook that has access to testInfo. Keep the hook’s own waits bounded so a failed test does not become a second timeout while collecting evidence.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Troubleshooting missing or unusable attachments

The report shows no image

  • Confirm the attachment call is awaited.
  • Check that the Allure Playwright reporter is enabled for the command that generated the results.
  • Generate the report from the same results directory used by the test run; stale results can make a new attachment appear to be missing.
  • Verify that the test reached the capture line. A navigation or assertion failure before it will prevent a manual attachment.

The file is present but not previewed

  • Set the exact image content type, such as image/png or image/jpeg.
  • Do not pass both body and path.
  • Ensure the Buffer is the screenshot returned by Playwright and that a path points to a readable image file.

Step attachment fails

Check your Playwright version. TestStepInfo.attach was added in v1.51. On an older release, attach with testInfo.attach() at test level or update the dependency after reviewing the change in your lockfile.

Automatic failure screenshots are absent

Confirm the effective configuration is screenshot: 'only-on-failure', then inspect the test output directory. Automatic capture is controlled by Playwright; whether and how it is displayed depends on the reporter and integration versions in use.

The screenshot is blank or captures the wrong state

  • Wait for the relevant locator or network-driven UI state instead of relying only on a fixed delay.
  • Make sure overlays, animations and consent dialogs are handled before capture.
  • Use the correct page or frame; a screenshot of the top-level page will not automatically target an embedded frame’s element.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Performance, storage and cost considerations

PNG screenshots are lossless and can be large, especially with full-page capture, high device scale factors or many parallel tests. Capture only the state needed to diagnose a failure, prefer element screenshots for component checks, and use failure-only mode when routine evidence is unnecessary. Keep artifact retention aligned with your CI storage policy; Allure results must remain available until report generation completes.

Manual screenshots add browser work at the point of capture. Automatic failure-only capture avoids that work for passing tests, while capturing every test gives broader audit coverage at the cost of more files and report data. If your CI runs shards, ensure each shard’s Allure result files are collected before the final report is built.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Or skip the browser setup

When you need a clean screenshot outside a Playwright test—or want to feed images to a pipeline—ScreenshotNeo returns a screenshot or PDF from one request. It accepts cookie/consent banners as a visitor and removes more than 60 known consent platforms, newsletter popups and chat widgets before capture; each cleanup step can be disabled. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed, and the response identifies the result with X-Page-Verdict and X-Billed headers. Its MCP server provides take_screenshot, get_page_info and capture_pdf tools for Claude, Cursor and other MCP clients.

Use the API documented at https://screenshotneo.com/docs/:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

The Free plan includes 1,000 shots per month with no card. Paid plans start at $5 for 3,000 shots; yearly billing gives two months free, and every feature is included on every plan. Sign up free to begin.

Final checklist

  1. Capture the intended page state with Playwright.
  2. Choose test-level, step-level or Allure-native placement.
  3. Pass either body or path, never both.
  4. Set the matching image content type.
  5. Await the attachment operation.
  6. Generate the Allure report from the current result files and verify the image in your pinned environment.

Frequently Asked Questions

Can I attach the same screenshot to both a test and a step?

Yes, but that creates two report attachments. Usually choose the location that best explains the evidence to avoid duplicate artifacts.

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

Does fullPage change how Allure stores the screenshot?

No. It changes what Playwright captures; you still attach the resulting Buffer or file with the appropriate image content type.

Should I use PNG or JPEG?

PNG is Playwright’s default and preserves lossless detail. JPEG can reduce artifact size when your visual checks do not need lossless output; set image/jpeg when you use 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.