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

To capture and compare a meaningful UI state in Playwright, first drive the page to that state, assert its important behavior, then use Playwright Test’s toHaveScreenshot() assertion. The first run creates a reference image; review it before committing it. Later runs compare against that baseline, and a failure’s image diff shows what changed while a trace helps explain how the page reached that point.

Build a visual test around a real interaction

A useful screenshot test records a user-visible state, not merely whatever happened to render after navigation. Use locators and actions to reproduce the interaction, then add focused assertions for its semantic outcome. The visual assertion checks how the state looks; it does not replace checks for text, URL, title, or form values.

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

test('shows the saved profile after editing', async ({ page }) => {
  await page.goto('/profile');
  await page.getByLabel('Display name').fill('Avery Chen');
  await page.getByRole('button', { name: 'Save' }).click();

  await expect(page).toHaveURL(/profile/);
  await expect(page.getByRole('status')).toHaveText('Profile saved');
  await expect(page).toHaveScreenshot('profile-saved.png');
});

Use a descriptive filename that identifies the state under review. Screenshot assertions are part of Playwright Test’s test runner; they are not a general-purpose screenshot comparison API for arbitrary Playwright scripts. Playwright documents this API as available since v1.23. Confirm option availability against the reference for the Playwright version installed in your project.

Choose what the screenshot should cover

Pick the smallest region that expresses the visual contract, unless the surrounding layout is part of what you need to protect.

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.
  • Whole page viewport: await expect(page).toHaveScreenshot('dashboard.png') checks the visible page view.
  • Specific component: await expect(page.getByRole('dialog')).toHaveScreenshot('confirmation-dialog.png') focuses the comparison on a locator, such as a dialog.
  • Full page: await expect(page).toHaveScreenshot({ fullPage: true }) captures the full page rather than only the viewport.
  • Clipped region: Use the screenshot assertion’s clip option when a specific page rectangle is the intended comparison area.

Page and locator screenshot assertions use the screenshot assertion API. See the PageAssertions API reference for the page-level options and the relevant locator assertion documentation for locator-level use.

Establish and review the baseline

  1. Run the test once in the environment you intend to use for visual review. With no reference image yet, Playwright creates the expected screenshot.
  2. Open the generated reference image and check that it shows the intended state, with the expected content and no loading or transient UI. Do not accept a baseline automatically just because the test produced one.
  3. Commit the reviewed reference image with the test. Treat it as a code-review artifact: a baseline update changes what future runs consider expected.
  4. On subsequent runs, inspect the actual image and diff when the assertion fails. Determine whether the change is a regression, an intentional design change requiring a reviewed baseline update, or incidental variation to control.

Playwright waits for two consecutive screenshots to match before comparing the final capture to the expectation. This reduces the chance of comparing a transient frame, but it cannot make changing content deterministic by itself. See the Visual comparisons guide.

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.

Keep comparisons stable without hiding real changes

Rendering is environment-sensitive. Playwright notes that browser rendering can vary with host operating system, browser version, settings, hardware, power source, headless mode, and other factors. Keep baseline generation and comparison on a consistent browser and platform where possible. If your project intentionally tests multiple environments, expect that you may need platform-specific baselines rather than treating every pixel difference as a product change.

Control content that changes on every run

Use screenshot controls only for genuine sources of noise, and make exclusions visible to maintainers.

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.
  • Disable animations: Screenshot assertions disable animations by default. Finite animations are fast-forwarded; infinite animations are canceled to their initial state for capture and resumed afterward.
  • Mask volatile regions: Mask timestamps, rotating content, or other elements that are not part of the visual contract using the assertion’s masking options.
  • Apply a screenshot stylesheet: A stylesheet can hide or normalize unstable elements. The documented stylePath option applies through Shadow DOM and inner frames and was added in v1.41; check your installed version before using it.
  • Set a deliberate capture region: Use a locator, full-page mode, or a clip to compare the intended part of the page instead of unrelated content.
  • Set tolerances sparingly: maxDiffPixels, maxDiffPixelRatio, and the perceptual threshold control how much difference is accepted. They are tolerance settings, not evidence that a change is harmless. Record why a tolerance is suitable; do not raise it just to silence unexplained diffs.

Options and version notes are in the PageAssertions API and Visual comparisons guide.

Diagnose a failed visual assertion

  1. Review the diff and actual image. Identify whether the changed pixels are in the component under test, surrounding layout, or a volatile region.
  2. Check the behavioral assertions. A changed URL, message, or form value can reveal that the test reached a different state rather than a rendering-only issue.
  3. Check environment consistency. Confirm that the comparison used the intended browser, operating system, headless mode, and other rendering conditions.
  4. Open the trace for sequence and context. Trace Viewer lets you navigate actions and inspect DOM snapshots and execution details around the failure. That can show whether an action failed, the wrong state appeared, or the page changed before capture.
  5. Update the baseline only for an accepted change. If the UI change is intended, review the new image and commit it with the relevant code; otherwise fix the regression or stabilize the true source of noise.

Use the Trace Viewer guide for reviewing actions, DOM snapshots, and failure context.

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

Use visual checks alongside semantic checks

Visual comparison answers whether the rendered pixels still match the approved appearance. Focused Playwright assertions answer whether a specific outcome—such as a URL, title, text, or form value—is correct. Use both when both appearance and behavior matter. Playwright’s assertions guide describes its retrying assertions. ARIA snapshots describe accessible structure, so they complement visual screenshots rather than replacing them; see Snapshot testing / ARIA snapshots.

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

Common problems and fixes

  • The first run creates a screenshot but no useful comparison: That is baseline creation. Inspect the generated reference image and commit it only after confirming it represents the intended state.
  • The test fails intermittently around capture: Make sure the interaction has reached its expected state with behavioral assertions. Identify changing content and stabilize only that content with animation handling, masking, or a stylesheet.
  • Many unrelated pixels differ on another machine: Align the browser and host environment with the baseline-producing environment, or maintain separate baselines for environments you deliberately compare.
  • A tolerance makes the test pass but obscures the reason: Review the diff and explain the accepted variation before changing a tolerance. Pixel-count and perceptual thresholds do not establish that a UI change is safe.
  • You are using toMatchSnapshot() for a screenshot: Playwright recommends toHaveScreenshot() for screenshot comparison; the SnapshotAssertions API cautions against using toMatchSnapshot() for screenshots.

Or skip the browser setup

If you need a screenshot without writing and maintaining a browser interaction test, ScreenshotNeo provides a one-request screenshot API. This is a direct URL capture rather than a replacement for Playwright’s interaction-driven baseline workflow.

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.

For example, capture a page to WebP with cURL:

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. ScreenshotNeo removes cookie/consent banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, and failed loads are not billed. Its MCP server lets AI agents take screenshots, and the Free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 shots. Sign up for 1,000 free screenshots a month with no card.

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.