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

Use Playwright Test’s toHaveScreenshot() assertion to capture a page or element and compare it with a committed baseline image. The first run creates the baseline if it does not exist; later runs compare new captures against it. Make the browser, operating system, viewport, fonts, and other rendering conditions consistent, then use masks or a screenshot-only stylesheet for dynamic regions. Adjust pixel tolerances only after inspecting the diff.

Compare a screenshot with a baseline using Playwright Test

The standard method is an assertion in a Playwright Test test. Give toHaveScreenshot() a filename to identify the reference image:

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

test('matches the existing baseline', async ({ page }) => {
  await page.goto('https://example.com');
  await expect(page).toHaveScreenshot('baseline.png');
});

Run the test with your project’s Playwright Test command, commonly npx playwright test. The assertion waits until two consecutive page screenshots are identical before comparing the stable capture with the expected snapshot. This helps avoid comparing a transient frame while the page is still changing, but it does not make changing application data deterministic; control that separately.

Playwright Test manages the expected screenshot lifecycle. If the named golden file is missing, the first run creates a reference screenshot. Subsequent runs compare against it and report visual differences when the result falls outside the configured tolerance. Snapshot files are stored in a test-specific snapshot directory. Keep that directory under version control with the test so the expected image is reviewed and available in later runs.

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.

Choose the right comparison scope

Compare the whole page

Use expect(page).toHaveScreenshot('landing.png') when the page’s overall layout and appearance are the contract being tested. This can catch unexpected changes outside a specific component, but it also makes the test sensitive to any unrelated dynamic region visible in the capture.

Compare one component or region

Use a locator assertion when the contract is a focused element. For example:

await expect(page.getByRole('button', { name: 'Save' }))
  .toHaveScreenshot('save-button.png');

This narrows the comparison to the button and is often a better fit for a component-level visual test. Choose a stable locator that identifies the intended element; a locator that matches a different element or becomes ambiguous can prevent the screenshot assertion from testing what you intended.

Use a captured buffer only for a custom pipeline

If you already have a screenshot buffer, Playwright also offers toMatchSnapshot(). For screenshot comparisons, the Playwright API recommends toHaveScreenshot(), which includes screenshot-specific stabilization and baseline handling. Prefer the built-in screenshot assertion unless your workflow genuinely requires you to capture and manage the image yourself.

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

Make captures repeatable before tuning tolerance

A visual comparison is meaningful only when the reference and new capture are rendered under comparable conditions. Browser rendering can vary with the host operating system, browser version and settings, hardware, power source, headless mode, and other environmental factors. Generate and compare baselines in the same browser project and, when possible, the same operating system, fonts, hardware, and headless configuration.

  • Keep the viewport and browser project aligned. A different viewport changes layout and may change what is visible. Use the same browser project and device-pixel assumptions for baseline generation and comparison.
  • Control hover state. Move the mouse away from hover-sensitive controls before capturing, or deliberately hover a neutral element. The pointer position can change menus, highlights, and other visual states.
  • Control animation. Screenshot assertions disable animations by default. Keep that behavior for ordinary visual-regression tests; test motion separately when the animation itself is what you need to verify.
  • Account for dynamic content. Timestamps, rotating ads, avatars, and live data can change between runs even when the interface code has not. Mask volatile regions or make their content deterministic in the test environment.
  • Keep capture scale consistent. The scale option accepts 'css' or 'device'; its documented default is 'css'. Choose intentionally and keep the setting consistent for your project.

For example, mask a changing clock and apply a stylesheet used only for screenshots:

await expect(page).toHaveScreenshot('dashboard.png', {
  mask: [page.locator('[data-testid="clock"]')],
  stylePath: './screenshot.css',
  animations: 'disabled',
  scale: 'css',
});

The mask option covers the matched region in the screenshot rather than requiring the rest of the page to be ignored. Use stylePath when a screenshot-specific stylesheet can hide dynamic areas or otherwise make the page repeatable. Keep such changes limited to capture conditions: hiding a region is appropriate only when that region is not part of the visual behavior the test is intended to protect.

Set tolerances according to the kind of difference

Playwright Test uses the pixelmatch library for image comparison. Its screenshot options let you express three different policies: a maximum count of differing pixels, a maximum fraction of the image that may differ, and a per-pixel color-difference threshold.

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.
Option What it controls When it is useful
maxDiffPixels An absolute budget for the number of mismatched pixels. Use when a fixed count is meaningful for the image sizes you compare.
maxDiffPixelRatio A mismatch budget expressed as a ratio from 0 to 1. Use when the acceptable proportion should scale with image size.
threshold The perceived color difference accepted for each pixel; the documented default is 0.2. Use to control sensitivity to small per-pixel color variation.

Here is an example that sets all three controls explicitly:

await expect(page).toHaveScreenshot('dashboard.png', {
  maxDiffPixels: 100,
  maxDiffPixelRatio: 0.001,
  threshold: 0.2,
});

These values are examples, not universal recommendations. There is no published tolerance that guarantees a meaningful result for every application. Start with strict settings, inspect the generated diff, and relax only the control that corresponds to an understood source of rendering noise, such as anti-aliasing. A broader threshold can hide real defects; an unnecessarily strict comparison can fail on harmless rendering variation. Record the chosen policy in project configuration so that tests use a consistent standard.

Approve intentional changes without losing review

When a change is intentional, regenerate the expected screenshots with:

npx playwright test --update-snapshots

Review the updated image files and their diffs before committing them. Updating snapshots changes what future test runs treat as correct; it does not establish that the interface change is desirable. Treat the image update as part of the code review, and commit the approved snapshot changes with the corresponding test or UI change.

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 #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
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common visual-comparison failures

The first run creates a screenshot instead of comparing

This is expected when the named golden file does not yet exist. Check the generated snapshot in the test-specific snapshots directory, review it, and commit it if it is the intended baseline. Do not assume that a newly generated image is automatically an approved reference.

A test fails after running on another machine or CI environment

Rendering can vary across operating systems, browser versions, settings, hardware, power conditions, and headless modes. Align the environment used to create and compare the baseline where possible. Also check that the browser project, viewport, screenshot scale, and fonts are consistent before increasing tolerances.

The diff highlights a timestamp, ad, avatar, or live value

That area is changing independently of the visual behavior under test. Make its data deterministic if feasible, or mask the specific locator with mask. If a screenshot-only stylesheet is a better fit, use stylePath to hide or stabilize the region. Avoid masking broad areas that contain interface elements the test should catch.

The mismatch is caused by hover or animation

Check the pointer position and whether a hover-sensitive control is active. Move the mouse away or intentionally set a neutral hover state. Animations are disabled by default for screenshot assertions; if you changed that behavior, restore it unless motion is the purpose of the test.

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.

Small visual noise causes too many failures

Inspect the diff first. If it shows known anti-aliasing or minor color variation, adjust the matching tolerance that addresses that specific noise. Use an absolute pixel budget for a fixed-size comparison or a ratio when the budget should vary with image size. Keep the selected values explicit and consistent. Do not raise every tolerance simply to make a failing test pass.

The update command changes many expected images

Snapshot updates may reflect a genuine broad UI change, an environment mismatch, or uncontrolled dynamic content. Review the changed files individually, verify the capture environment, and stabilize volatile regions before approving the new references. If the change is not intentional, restore the expected files and investigate the underlying rendering difference.

Or skip the browser setup

If you need a screenshot returned by an API rather than a Playwright baseline assertion, ScreenshotNeo provides a screenshot API and MCP server. A single GET request can return an image or PDF; the following cURL example saves a WebP capture of the target URL. See the ScreenshotNeo API documentation for request options.

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

ScreenshotNeo accepts cookie or consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the page verdict and billing status in headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. It is an API capture option, not a replacement for Playwright’s baseline comparison and test workflow. Sign up free for 1,000 screenshots a month with no card.

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

How to choose a reliable visual-regression workflow

For a maintainable test suite, decide what visual contract each assertion protects and keep its capture conditions explicit. Use page assertions for page-wide layout and locator assertions for isolated components. Stabilize data and rendering before changing tolerance settings. Store baselines with the test code and review every deliberate snapshot update. This keeps a diff useful: it should flag a meaningful visual change, not merely report that two captures were produced under different conditions.

Frequently Asked Questions

Can I compare a PNG baseline with a WebP screenshot?

Playwright’s screenshot API documents PNG as the default format and supports a lossless WebP when the screenshot filename ends in .webp. Keep the expected and actual screenshot workflow aligned by using the same intended filename and format.

Does a screenshot assertion prove the page is functionally correct?

No. It checks rendered appearance against an expected image; it does not replace assertions for navigation, accessibility, interaction, or application data.

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.

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