The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Use Playwright Test’s built-in expect(page).toHaveScreenshot() assertion. Its first run creates a reference image; later runs compare new screenshots against that baseline and report visual differences. Review and commit the generated snapshots, keep baseline generation and CI rendering environments consistent, and update references only after inspecting an intentional change.
What Playwright visual regression testing does
Playwright Test captures a page or element and compares its pixels with a saved reference image. This is a screenshot assertion provided by the Playwright test runner; it is not a standalone assertion for arbitrary scripts outside Playwright Test. The official Visual comparisons guide and page assertion API describe the workflow and options.
The first run has no reference to compare, so Playwright reports a missing snapshot and writes an image for review. On later runs it captures again and compares the result. Playwright takes screenshots until two consecutive captures match, then uses the last image for comparison or as the newly generated baseline. Snapshot names include browser and platform information; with multiple projects, the project name is included too.
Install and write a first screenshot test
Install Playwright Test
If the project does not already use Playwright Test, add it with:
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
#1 Best Overall
- 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.
npm init playwright@latest
Follow the setup prompts for the project’s language and configuration. If the package is already installed, create a test file in the configured test directory and use the test runner already defined by the project.
Capture a page
This TypeScript example visits a page and checks its viewport screenshot:
import { test, expect } from '@playwright/test';
test('landing page visual layout', async ({ page }) => {
await page.goto('https://example.com');
await expect(page).toHaveScreenshot('landing.png');
});
Run the test with:
npx playwright test
Inspect the generated image rather than accepting it automatically. Once the image represents the intended appearance, commit the snapshot with the test. By default, Playwright organizes snapshots alongside the test’s snapshot directory; named files make their purpose easier to recognize. An explicit .png name produces a lossless PNG; use .webp for lossless WebP. If you omit the name, Playwright derives one from the test and snapshot sequence.
Review and update a baseline
Snapshots are part of the test’s expected behavior, so store them in version control. When a legitimate design change alters the image, run:
Rank #2
- 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.
npx playwright test --update-snapshots
Review the changed reference images, then commit them with the product change. Updating snapshots without reviewing them can turn an unintended regression into the new expected result.
Make baseline captures consistent with CI
Playwright’s guidance is direct: “For consistent screenshots, run tests in the same environment where the baseline screenshots were generated.” Operating system, browser version, browser settings, hardware, power source, and headless mode can affect rendering. Use the same OS, browser build, project configuration, and installed fonts for baseline creation and CI comparison where practical. A reference generated on one rendering stack may differ from a run on another even when the application code has not changed.
Choose the screenshot scope and project intentionally. Use page screenshots when the page or viewport is the behavior being tested; use a locator assertion when only a component matters. Use fullPage: true when the test needs the whole scrollable page rather than just the visible viewport. If browsers or projects render differently, let each project have the references appropriate to it instead of comparing unlike environments.
Capture a specific component or the full page
test('checkout panel visual layout', async ({ page }) => {
await page.goto('https://example.com/checkout');
await expect(page.locator('[data-testid="checkout-panel"]))
.toHaveScreenshot('checkout-panel.png');
});
test('full page visual layout', async ({ page }) => {
await page.goto('https://example.com');
await expect(page).toHaveScreenshot('full-page.png', { fullPage: true });
});
The locator selector must match an element in the page. Prefer a stable test identifier or selector whose meaning is tied to the component under test.
Recommended Free Tools
Rank #3
- 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 changing content without hiding real regressions
Playwright reduces some transient variation automatically: screenshot assertions wait for two consecutive matching captures, disable animations by default, fast-forward finite animations, cancel infinite animations during capture, and hide the caret. These safeguards do not make live data or every rendering difference deterministic.
If a changing timestamp, avatar, advertisement, or other area is irrelevant to the behavior under test, mask it or use a stylesheet through stylePath to hide or adjust it. A stylesheet can also affect Shadow DOM and inner frames. Keep the exclusion as narrow as possible: once an area is masked or hidden, the test no longer verifies how that area looks.
Mask only irrelevant regions
test('account page visual layout', async ({ page }) => {
await page.goto('https://example.com/account');
await expect(page).toHaveScreenshot('account.png', {
mask: [page.locator('[data-testid="live-clock"]')],
});
});
For dynamic content that cannot be isolated with a mask, a dedicated stylesheet can hide or normalize it during capture. Keep such rules scoped to the screenshot assertion so the application’s normal behavior is still exercised outside the visual comparison.
Tune visual comparison tolerance
Playwright uses pixelmatch for visual comparisons. The options below govern different parts of the comparison, so do not treat them as interchangeable. The documented default for threshold is 0.2; the total-difference limits are unset unless you configure them.
Rank #4
- 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
| Option | What it controls | Documented default |
|---|---|---|
threshold |
How much perceived color difference an individual pixel may have before it counts as different; range is 0 (strict) to 1 (lax). | 0.2 |
maxDiffPixels |
The maximum number of pixels allowed to differ. | Unset |
maxDiffPixelRatio |
The maximum fraction of all image pixels allowed to differ. | Unset |
Start with the defaults and inspect actual diff images. Relax tolerance only enough to account for harmless variation; a high per-pixel threshold or broad total-difference allowance can conceal a meaningful styling or layout change. There is no universal tolerance that suits every application.
Set shared expectation defaults
Configuration can apply screenshot expectation defaults globally or per project. This example sets an illustrative pixel cap, not a generally recommended value:
import { defineConfig } from '@playwright/test';
export default defineConfig({
expect: {
toHaveScreenshot: {
maxDiffPixels: 100,
// Add a threshold only if observed rendering needs it.
},
},
});
For the full configuration surface, see the official Playwright configuration reference.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Common failures and practical fixes
- “Snapshot missing” on the first run: This is expected when no reference exists. Inspect the actual image created by Playwright; keep and commit it only if it is the intended appearance.
- Unexpected differences on CI: Check whether baseline generation and CI use the same operating system, browser build, fonts, project settings, and headless mode. Make the environments alike before loosening comparison tolerance.
- Flaky diffs from live data or overlays: Identify whether the changing region is part of the visual contract. Mask or style out only irrelevant dynamic content; do not hide a component whose appearance the test is meant to protect.
- Many tiny pixel changes: Inspect the diff and rendering environment first. If the differences are genuinely harmless, adjust
thresholdfor per-pixel sensitivity or set a carefully limited total cap withmaxDiffPixelsormaxDiffPixelRatio. - A baseline update makes a failing test pass: Do not treat an update as a fix by itself. Review the changed image to establish that the visual change is intentional, then commit the reviewed reference alongside the implementation change.
- Locator screenshot fails to match the intended element: Verify the selector resolves to the component under test and remains stable. Use a page assertion instead if the intended behavior is the full page or viewport.
Or skip the browser setup
If the goal is to capture a website image rather than maintain Playwright’s version-controlled visual assertions, ScreenshotNeo provides a screenshot API and MCP server. It is not a replacement for Playwright’s baseline comparison workflow; it can produce the capture your own workflow consumes.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallBest Value
- 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.
One GET request returns an image or PDF. For example, save a PNG from a URL with cURL:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.png
See the ScreenshotNeo API documentation for request options. Cookie banners, newsletter popups, and chat widgets are removed before capture; those cleanup steps can be turned off. Bot checks/CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers report the page verdict and billing status. An MCP server exposes screenshot 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. Sign up for free ScreenshotNeo access.
Frequently Asked Questions
Can I use `toHaveScreenshot()` in a script outside Playwright Test?
No. Screenshot assertions are supported by Playwright Test’s test runner.
Which image formats can a named snapshot use?
Use `.png` for PNG or `.webp` for lossless WebP.
Should I choose `threshold` or `maxDiffPixels` first?
They address different things: `threshold` decides whether an individual pixel counts as different, while `maxDiffPixels` and `maxDiffPixelRatio` cap the total differences.
Quick Recap
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.

