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

Use Playwright Test’s toHaveScreenshot() assertion to compare a page or element with a saved visual baseline. Review and commit the baseline generated on the first run, then update it only after confirming that a change is intentional. Run captures and comparisons in a consistent browser and operating-system environment to reduce unrelated differences.

Compare a page with a screenshot baseline

toHaveScreenshot() is Playwright Test’s screenshot-specific assertion. On the first run, Playwright takes screenshots until two consecutive captures match, then saves the last image as the reference. Later runs compare new captures with that baseline. See the Playwright visual comparisons guide.

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

test('homepage visual baseline', async ({ page }) => {
  await page.goto('/');
  await expect(page).toHaveScreenshot('homepage.png');
});

This example assumes a configured Playwright Test project and a page route available at /. A locator assertion uses the same approach for a component rather than the whole page:

await expect(page.locator('[data-testid="summary"]')).toHaveScreenshot('summary.png');

Use screenshot assertions for image output; toMatchSnapshot() is intended for strings or buffers and is not the recommended screenshot-specific assertion. Snapshot assertions require the Playwright Test runner. See the SnapshotAssertions API and PageAssertions API.

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.

Generate, review, and update baselines

  1. Run the test once. Playwright creates the reference image after its initial matching captures. Locate it in the configured snapshot output and inspect it for the intended page, viewport, and state.
  2. Commit the reviewed image. Keep the baseline with the test in version control. Default snapshot naming incorporates the browser and platform, or project name when configured; separate projects can therefore have distinct references.
  3. Run the test again in the intended environment. Playwright compares the new screenshot with the saved reference and reports visual differences.
  4. Update only for an approved visual change. Run npx playwright test --update-snapshots, inspect the new images, and commit the approved references with the corresponding change. Avoid updating snapshots just to make an unexplained failure disappear.

Choose screenshot comparison tolerances

Playwright exposes settings for two different questions: how much an individual pixel may differ, and how much of the complete image may differ. Configure them per assertion or, when the same policy suits the suite, globally or per project through expect.toHaveScreenshot. Check the API documentation matching your installed Playwright version because options and defaults can change.

Option What it controls How to use it
threshold Allowed perceived color difference for a pixel pair. The API documents a default of 0.2 for pixelmatch’s YIQ color space. Lower values are stricter; higher values allow more per-pixel variation.
maxDiffPixels Absolute maximum number of differing pixels. The visual guide shows 100 as an example configuration, not a universal recommendation.
maxDiffPixelRatio Maximum fraction of the total image allowed to differ. Useful when screenshot dimensions vary and a proportion-based cap is preferable.

For example, a per-call allowance can be set like this:

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.
await expect(page).toHaveScreenshot('homepage.png', {
  threshold: 0.2,
  maxDiffPixels: 100,
});

These sample values illustrate the options; they are not a recommendation for every project. Raising tolerances can conceal real regressions. First investigate unstable page state, fonts, animation, pointer position, viewport, browser, and host environment.

Reduce false visual differences

Keep the rendering environment consistent

Playwright warns that “Browser rendering can vary based on the host OS, version, settings, hardware, power source (battery vs. power adapter), headless mode, and other factors.” Generate and compare snapshots in the same pinned or otherwise stable CI environment where possible. If materially different browser or platform projects are required, maintain their expected baselines separately. The snapshot guide also explains platform-specific naming.

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.
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.

Control dynamic page content

  • Use deterministic test data and wait for the UI state that matters before capturing.
  • Ensure fonts and other required assets have loaded; differing font availability can change layout and glyph rendering.
  • Disable or neutralize animations and other known volatile elements when they are not part of what the test is meant to verify.
  • Use Playwright’s documented stylePath option to inject CSS that filters dynamic elements during a screenshot.
  • Set or remove the pointer deliberately. Hover effects are captured if present, so move the pointer away or establish the intended hover state before the assertion.

There is no single stabilization recipe for every application: keep meaningful visual behavior under test and suppress only the variability that is irrelevant to that test.

Choose the image format

Named screenshot snapshots use PNG by default. A .webp suffix selects WebP; Playwright documents this snapshot format as lossless. Use the format that fits the test repository and its image-review workflow.

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

Troubleshoot screenshot comparison failures

Symptom Likely cause What to do
The baseline differs between a developer machine and CI. Host OS, browser version, settings, hardware, headless mode, or fonts differ. Compare in a consistent environment and use separate project baselines when rendering environments intentionally differ.
The diff changes from run to run. Unstable data, animation, incomplete loading, dynamic content, or a varying UI state. Make test inputs deterministic, wait for the desired state and assets, and suppress irrelevant dynamic areas with stylePath where appropriate.
A control changes appearance unexpectedly. The pointer is hovering over it during capture. Move the pointer away or explicitly set the hover state the test is supposed to check.
Small anti-aliasing or color variations fail the assertion. The per-pixel threshold may be too strict for the rendering environment. Investigate the environment first; if the variation is acceptable, adjust the threshold deliberately rather than broadly relaxing the test.
A small changed region fails despite an otherwise matching page. The total-difference cap is exceeded. Inspect the diff. Adjust maxDiffPixels or maxDiffPixelRatio only if that amount of change is acceptable for this assertion.
Updating snapshots makes the failure pass, but the change is unexplained. The baseline was replaced without review. Restore or reject the update, inspect actual and expected images, and update with --update-snapshots only after approving the visual change.
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 file rather than an in-test visual regression assertion, ScreenshotNeo returns a screenshot from one GET request. It removes cookie/consent banners, newsletter popups, and chat widgets before the shot; bot checks, blank pages, and failed loads are never billed; and 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.

cURL example (see the ScreenshotNeo API documentation):

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

This captures an external page to a file; it does not replace Playwright’s baseline comparison inside a test. Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.

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.

Frequently Asked Questions

Can I compare a component instead of a full page?

Yes. Use toHaveScreenshot() on a locator, such as page.locator('[data-testid="summary"]').

Can I use WebP screenshot baselines?

Yes. Give the named screenshot a .webp suffix; Playwright documents WebP as lossless.

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.

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.