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

To capture a screenshot after every logical Playwright action, wrap each action in test.step(), call page.screenshot() after the action completes, and attach the returned PNG with step.attach(). The attachment is associated with that named step in reporters that display step attachments.

Capture a screenshot inside each test.step()

Playwright does not automatically turn every page.click(), navigation, or assertion into a report step. You define the diagnostic boundaries explicitly with test.step(). The callback receives a TestStepInfo object; use it to attach the screenshot before the callback returns.

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

test('checkout flow', async ({ page }) => {
  await test.step('open cart', async step => {
    await page.goto('https://example.com/cart');
    const screenshot = await page.screenshot();
    await step.attach('after-open-cart', {
      body: screenshot,
      contentType: 'image/png',
    });
  });

  await test.step('submit order', async step => {
    await page.getByRole('button', { name: 'Submit order' }).click();
    const screenshot = await page.screenshot();
    await step.attach('after-submit-order', {
      body: screenshot,
      contentType: 'image/png',
    });
  });
});

With no path option, page.screenshot() returns image bytes in memory. Those bytes are passed directly to step.attach(), so there is no temporary file to clean up. The attachment name is the label shown by reporters that support step-level attachments.

What the order of operations means

  1. Perform the navigation, click, fill, or other action.
  2. Await the action so the page reflects its completed state.
  3. Await page.screenshot() to capture that state.
  4. Await step.attach() before leaving the step callback.

If an action throws, the lines after it do not run, so no “after” image is attached for that failed transition. You can add a separate failure hook when you need evidence of the final failed state.

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.
#1 Best Overall
Sale
Logitech Brio 101 Full HD 1080p Webcam for Streaming and Meetings - Black
  • Compatible with Nintendo Switch 2’s new GameChat mode
  • Auto-Light Balance: RightLight boosts brightness by up to 50%, reducing shadows so you look your best—compared to previous-generation Logitech webcams (1)
  • Privacy with a Slide: The integrated webcam cover makes it easy to get total, reliable privacy when you're not on a video call
  • Built-In Mic: The built-in microphone lets others hear you clearly during video calls
  • Easy Plug-And-Play: The Brio 101 works with most video calling platforms, including Microsoft Teams, Zoom and Google Meet—no hassle; it just works

A reusable screenshot-step helper

Repeating the capture and attachment code is manageable for two steps but noisy in longer flows. A helper can standardize the attachment name and guarantee that the screenshot happens after the supplied action.

import { test, type Page } from '@playwright/test';

type StepBody = (step: any) => Promise<void>;

async function screenshotStep(
  page: Page,
  title: string,
  body: StepBody,
) {
  await test.step(title, async step => {
    await body(step);
    const image = await page.screenshot();
    await step.attach('screenshot', {
      body: image,
      contentType: 'image/png',
    });
  });
}

test('profile update', async ({ page }) => {
  await screenshotStep(page, 'open profile', async () => {
    await page.goto('https://example.com/profile');
  });

  await screenshotStep(page, 'save profile', async () => {
    await page.getByLabel('Display name').fill('Ada');
    await page.getByRole('button', { name: 'Save' }).click();
  });
});

The practical rule is more important than the exact TypeScript type: execute the step body first, then capture and attach. In a project with strict typing, replace any with the TestStepInfo type exposed by your installed Playwright version, or keep the callback type local to your test utilities.

Choose the right screenshot scope

Viewport or full page

The default screenshot captures the current viewport. For a long, scrollable document, request a full-page image:

const image = await page.screenshot({ fullPage: true });
await step.attach('full-page', {
  body: image,
  contentType: 'image/png',
});

Full-page images are useful for layout diagnostics but can be large. Use viewport captures for a chronological action log, and reserve full-page captures for steps where below-the-fold content matters.

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

In-memory attachment or file output

Use an in-memory buffer when the report is the primary destination:

Rank #2
Sale
Logitech C270 720p Webcam Plug-and-Play Wide Screen Video Calling - Black
  • Compatible with Nintendo Switch 2’s new GameChat mode
  • Crisp HD 720p/30 fps video calls with diagonal 55° field of view and auto light correction. Compatible with popular platforms including Skype and Zoom.
  • The built-in noise-reducing mic makes sure your voice comes across clearly up to 1.5 meters away, even if you’re in busy surroundings.
  • C270’s RightLight 2 feature adjusts to lighting conditions, producing brighter, contrasted images to help you look good in all your conference calls.
  • The adjustable universal clip lets you attach the camera securely to your screen or laptop, or fold the clip and set the webcam on a shelf. You’re always ready for your next video call.
const image = await page.screenshot();

Use a path when another tool needs a physical file:

await page.screenshot({ path: 'artifacts/after-submit.png' });

A path alone does not associate the image with a test step. If you need both a file and a report attachment, capture the buffer, write it with your own file utility, and pass the same buffer to step.attach().

PNG, visual assertions, and diagnostics

page.screenshot() plus step.attach() creates a chronological diagnostic record. It answers “what did the page look like after this transition?” It is different from expect(page).toHaveScreenshot(), which is a Playwright Test visual-regression assertion that compares the current rendering with a baseline. Use assertions for intentional pixel comparison; use step attachments for investigation and audit trails.

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

When you need one screenshot per test

If the requirement is one final image after every test, not one image after every logical action, use test.afterEach() and attach through testInfo:

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

test.afterEach(async ({ page }, testInfo) => {
  const image = await page.screenshot();
  await testInfo.attach('final-page', {
    body: image,
    contentType: 'image/png',
  });
});

This hook runs once per test. On a failure, the page may be somewhere in the middle of the flow rather than at the last successful action. For that reason, per-step capture gives better diagnostic granularity when every transition matters. Use the hook when a final-state artifact is sufficient and you want less report size and runtime overhead.

Rank #3
Sale
NexiGo N60 1080P Webcam with Microphone, Software Control & Privacy Cover, USB HD Computer Web Camera, Plug and Play, for Zoom/Skype/Teams, Conferencing and Video Calling
  • 【Full HD 1080P Webcam】Powered by a 1080p FHD two-MP CMOS, the NexiGo N60 Webcam produces exceptionally sharp and clear videos at resolutions up to 1920 x 1080 with 30fps. The 3.6mm glass lens provides a crisp image at fixed distances and is optimized between 19.6 inches to 13 feet, making it ideal for almost any indoor use.
  • 【Wide Compatibility】Works with USB 2.0/3.0, no additional drivers required. Ready to use in approximately one minute or less on any compatible device. Compatible with Mac OS X 10.7 and higher / Windows 7, 8, 10 & 11 / Android 4.0 or higher / Linux 2.6.24 / Chrome OS 29.0.1547 / Ubuntu Version 10.04 or above. Not compatible with XBOX/PS4/PS5.
  • 【Built-in Noise-Cancelling Microphone】The built-in noise-canceling microphone reduces ambient noise to enhance the sound quality of your video. Great for Zoom / Facetime / Video Calling / OBS / Twitch / Facebook / YouTube / Conferencing / Gaming / Streaming / Recording / Online School.
  • 【USB Webcam with Privacy Protection Cover】The privacy cover blocks the lens when the webcam is not in use. It's perfect to help provide security and peace of mind to anyone, from individuals to large companies. 【Note:】Please contact our support for firmware update if you have noticed any audio delays.
  • 【Wide Compatibility】Works with USB 2.0/3.0, no additional drivers required. Ready to use in approximately one minute or less on any compatible device. Compatible with Mac OS X 10.7 and higher / Windows 7, 10 & 11, Pro / Android 4.0 or higher / Linux 2.6.24 / Chrome OS 29.0.1547 / Ubuntu Version 10.04 or above. Not compatible with XBOX/PS4/PS5.

Make the screenshots useful and affordable

Give steps meaningful boundaries

  • Name steps after user-visible outcomes, such as “open cart” or “submit order,” rather than generic names like “step 1.”
  • Put the action and its immediate assertions in the same step when the screenshot should show the result of both.
  • Do not wrap every low-level locator operation if that produces hundreds of nearly identical images. Capture at business-significant transitions.

Control image volume

Every capture consumes memory while the test runs and storage in the resulting report. Viewport PNGs are usually a better default for a step history. Use fullPage: true only where the complete document is part of the question. If a flow contains loops, consider capturing only the first iteration, the final iteration, and failures.

Reporter visibility

step.attach() attributes the file to the step, but the display depends on the reporter. Verify that the reporter used in CI renders step attachments; otherwise, the test can still pass while the image is stored somewhere that your team does not inspect. Keep the attachment name stable so developers can find it across runs.

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

Common failures and fixes

No screenshot appears in the report

  • Cause: the selected reporter does not display step attachments. Fix: inspect its attachment support or open the raw test-results directory.
  • Cause: the callback exits before step.attach() is awaited. Fix: await both the screenshot and attachment calls.
  • Cause: the action failed first. Fix: add a failure hook or capture before the risky action when you need a pre-action image.

The image shows the old page state

Await the navigation or interaction that changes the UI. For state that updates asynchronously after a click, wait for a specific visible result (for example, a success message) before calling page.screenshot(). A screenshot captures exactly the pixels available at that instant; it does not wait for your application’s business state automatically.

The helper has TypeScript errors

Type the callback with the TestStepInfo type from your installed Playwright package, or use a small local interface containing the attach method. The callback must return a promise, and attach must receive image bytes plus a MIME type.

The report becomes too large or slow

  • Capture the viewport instead of the full page.
  • Reduce the number of logical capture points.
  • Attach only PNG data needed for diagnosis and avoid duplicating the same image as both a path and an attachment unless another consumer requires the file.

A failed test has no final screenshot

An exception before the screenshot line prevents that line from running. Add a test.afterEach() capture for a final-state fallback, while retaining per-step captures for successful transitions. The two approaches serve different purposes and can coexist if the extra artifact is worth the report size.

Rank #4
Sale
EMEET C960 1080P Webcam with Microphone, 2 Mics, 90° FOV, Computer Camera
  • 1080P Webcam with Cover for Video Calls - EMEET computer webcam provides design and Optimization for professional video streaming. Realistic 1920 x 1080p video, 5-layer anti-glare lens, providing smooth video. C960 computer camera delivers 1920x1080 video with fixed focus (11.8–118.1 inches), so as to provide a clearer image. C960 USB webcam has a cover and can be removed automatically to meet your needs for privacy. For optimal image performance, use the webcam in a well-lit environment.
  • Built-in 2 Omnidirectional Mics - EMEET webcam with microphone for desktop features 2 built-in omnidirectional microphones, picking up your voice to create clear audio for communication. When installing the webcam, select EMEET C960 as the default microphone input device in your computer and video applications and select C960 as the default device in Zoom/Teams and ensure microphone permissions are enabled for proper use. Please note that C960 does not include built-in speakers.
  • Automatic Light Adjustment - Automatic exposure adjustment is applied in EMEET HD webcam 1080p so that the streaming webcam can deliver stable image performance. EMEET C960 camera for computer also features color adjustment and exposure optimization to help you look your best. For optimal video quality, it is recommended to use the webcam in normal or well-lit environments and select suitable video settings in your application. Proper lighting helps achieve a clearer and more balanced image.
  • Plug-and-Play & Upgraded USB Connectivity - New C960 webcam features both USB Type-A & A-to-C adapter connections for wider compatibility. For stable performance, connect the webcam directly to the computer's main USB port and ensure the device is recognized correctly. If a hub or docking station is used, please ensure it provides sufficient power and stable data transmission, as limited ports may affect performance. 90° wide-angle lens captures more participants without frequent adjustments.
  • High Compatibility & Multi Application - C960 webcam for laptop is compatible with Windows 10/11, macOS 10.14+, and Android TV 7.0+. Not supported: Windows Hello, TVs, tablets, or game consoles. It works with Zoom, Teams, Facetime, Google Meet, YouTube and more. Please select C960 webcam as the default camera and microphone device in your application and ensure camera/microphone permissions are enabled, especially on macOS. (Tips: Incompatible with Windows Hello)
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup:

If you need a screenshot of a URL rather than a Playwright test’s step-by-step diagnostic record, ScreenshotNeo returns an image or PDF through one request. Its capture can accept cookie or consent banners like a visitor and remove more than 60 known consent platforms, newsletter popups, and chat widgets before the shot; each cleanup action can be disabled. Bot checks or 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. It also provides an MCP server with take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.

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

Use the ScreenshotNeo documentation for the complete option list. This one-call example captures Stripe as WebP:

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

The same request in Python:

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)

And Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

ScreenshotNeo supports full-page captures with lazy images loaded, CSS-selector element captures, dark mode, 12 device presets plus custom viewports, retina scale, PDF paper and page-range controls, custom CSS and JavaScript, pre-capture clicks, hidden selectors, selector or delay or network-idle waits, request and resource blocking, headers, cookies, user agents, authorization, timezone and geolocation, transparent backgrounds, resizing, chosen cache TTLs, signed image links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, a usage API, an OpenAPI specification, and compatible parameter names used by other screenshot APIs.

The Free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 shots; every feature is on every plan. Create a free ScreenshotNeo account to start.

FAQ

Does Playwright screenshot every page.click() automatically?

No. Automatic capture applies only to code that explicitly wraps the action in test.step() and attaches an image.

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

Can I attach a JPEG instead of a PNG?

Yes. Pass the screenshot bytes and set the attachment’s contentType to the format you captured, such as image/jpeg.

Best Value
Logitech C920x HD Pro PC Webcam Full 1080p/30fps Video - Black
  • Compatible with Nintendo Switch 2’s new GameChat mode
  • HD lighting adjustment and autofocus: The Logitech webcam automatically fine-tunes the lighting, producing bright, razor-sharp images even in low-light settings. This makes it a great webcam for streaming and an ideal web camera for laptop use
  • Advanced capture software: Easily create and share video content with this Logitech camera that is suitable for use as a desktop computer camera or a monitor webcam
  • Stereo audio with dual mics: Capture natural sound during calls and recorded videos with this 1080p webcam, great as a video conference camera or a computer webcam
  • Full HD 1080p video calling and recording at 30 fps. You'll make a strong impression with this PC webcam that features crisp, clearly detailed, and vibrantly colored video

Should I use a step attachment for visual regression?

No. Use expect(page).toHaveScreenshot() when the purpose is baseline comparison; use attachments for diagnostic history.

Frequently Asked Questions

Does Playwright screenshot every page.click automatically?

No. Only actions inside your explicit test.step blocks are captured by the shown pattern.

Can I capture after each test instead of each step?

Yes. Register test.afterEach and attach a screenshot through testInfo for one final image per test.

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.

What if my reporter does not show step attachments?

Check the reporter’s attachment support or inspect the raw test-results artifacts; step.attach still associates the file with the step.

Quick Recap

SaleBestseller No. 1
Logitech Brio 101 Full HD 1080p Webcam for Streaming and Meetings - Black
Logitech Brio 101 Full HD 1080p Webcam for Streaming and Meetings - Black
Compatible with Nintendo Switch 2’s new GameChat mode; Built-In Mic: The built-in microphone lets others hear you clearly during video calls
$35.90
SaleBestseller No. 2
Logitech C270 720p Webcam Plug-and-Play Wide Screen Video Calling - Black
Logitech C270 720p Webcam Plug-and-Play Wide Screen Video Calling - Black
Compatible with Nintendo Switch 2’s new GameChat mode
$16.89
Bestseller No. 5
Logitech C920x HD Pro PC Webcam Full 1080p/30fps Video - Black
Logitech C920x HD Pro PC Webcam Full 1080p/30fps Video - Black
Compatible with Nintendo Switch 2’s new GameChat mode; Fully compatible with Windows 11
$69.99

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.