October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk6 min

How to Add Visual Testing to Functional Tests with Playwright

Learn to add Playwright screenshot assertions to functional tests, create and review baselines, stabilize visual comparisons, and run them reliably in CI.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Add visual testing to a browser-based functional test by taking a screenshot at a meaningful, already-verified UI state and comparing it with a reviewed baseline. In Playwright Test, use await expect(page).toHaveScreenshot() for a page or call it on a locator to check a component. Keep behavioral assertions: functional checks verify what the app does; screenshot assertions check how it looks.

What visual testing adds to a functional test

A functional test can confirm that navigation succeeds, a button works, or an order summary appears while missing an unintended change in spacing, color, typography, or layout. A screenshot assertion complements those checks by comparing rendered pixels with an approved reference. Neither replaces the other.

Playwright Test generates a reference screenshot when you first establish one, then compares later captures against it. For a new reference, the runner can capture until two consecutive screenshots match. See the Playwright screenshot comparison documentation.

Add a screenshot assertion to an existing Playwright test

Put the visual assertion after the test has reached and verified the state you want to protect. A locator assertion narrows the visual contract to a component; a page assertion covers the full page.

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.
import { test, expect } from '@playwright/test';

test('checkout summary looks correct', async ({ page }) => {
  await page.goto('/checkout');

  // Keep functional assertions that verify the expected behavior and state.
  await expect(page.getByRole('heading', { name: 'Your order' })).toBeVisible();

  // Add a visual assertion for the rendered component.
  await expect(page.locator('[data-testid="order-summary"]'))
    .toHaveScreenshot('order-summary.png');
});

The route, heading, and selector are examples; replace them with stable identifiers and a state meaningful to your application. If the entire page is the visual contract, use await expect(page).toHaveScreenshot(). Assertion options, including comparison thresholds and stylesheets, are documented in Playwright’s snapshot guide.

Choose the state before choosing the screenshot area

  • Run the user journey or setup steps that put the interface into the state you care about.
  • Assert the important behavior and state first, such as a confirmation heading being visible.
  • Capture the smallest region that represents the intended visual contract. A component screenshot can avoid unrelated page changes; a page screenshot can catch interactions between regions.

Create, review, and update baselines

Generate the initial reference

Run the new test with your normal Playwright command. On its first run, Playwright creates a reference image for the screenshot assertion. Inspect the image to confirm it represents the intended state, then commit it alongside the test.

Review future differences instead of accepting them automatically

When a later run differs, inspect the actual image and diff. Decide whether it is an unintended regression, an intentional UI change, or rendering noise. A changed screenshot is evidence to review, not an automatic instruction to replace the baseline.

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.

For an intentional change, regenerate references with:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
npx playwright test --update-snapshots

Review the resulting snapshot files and commit them with the implementation change. Avoid updating snapshots wholesale just to make a failing run green; that can turn the reference into a record of a regression.

Stabilize rendering and dynamic content

Visual comparisons depend on more than application code. Playwright notes that operating system, browser version, browser settings, hardware, power source, and headless mode can affect screenshots. Its guidance is to run tests in the same environment used to generate the baseline; its best practices also call for matching the operating system and browser versions. See screenshot guidance and Playwright best practices.

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.

Keep the capture state predictable

  • Use consistent test data and make the same route and UI state reproducible on each run.
  • Use the same browser and operating-system environment for baseline generation and comparison.
  • If unrelated content changes unpredictably, use Playwright’s screenshot stylesheet option to suppress only that volatile region.
  • Keep suppression narrow: hiding too much can conceal a genuine layout or content regression.

Set thresholds only for a known reason

Playwright offers options such as maxDiffPixels to tolerate a defined amount of difference. Tune a threshold against representative changes and review failures; do not use it to silence unexplained diffs. A pixel difference may indicate a font, asset, style, or layout change, an intentional product update, or environmental variance. The diff needs a human decision.

Run visual checks in CI

CI should install the project dependencies, install the required Playwright browsers and their dependencies, and run the tests. A container can help keep screenshot rendering consistent between machines. Playwright recommends one worker by default in CI to prioritize stability; teams with suitable infrastructure can use sharding for broader parallelism. Follow the current Playwright CI guide for setup details.

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

Review snapshot changes in the same code review as the UI change. If a CI visual test fails unexpectedly, inspect its screenshot diff and use a trace to understand how the test reached that state. Playwright recommends Trace Viewer for CI debugging and documents configuring traces for CI, including collecting them on the first retry: Trace Viewer and best practices.

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

Common failures and how to respond

Symptom Likely cause Response
The first run creates a snapshot No reference exists yet for that assertion. Inspect the generated image, confirm it shows the intended state, and commit it with the test.
A screenshot differs on a later run The UI changed, the test reached a different state, or the rendering environment varies. Inspect actual, expected, and diff images; verify the functional state and environment before deciding whether to update the baseline.
CI fails while local runs pass The browser, operating system, or other rendering conditions differ; the test may also be flaky. Align the baseline and CI environment, then inspect screenshots and a trace of the failing run.
Unrelated dynamic content creates noise Content in the capture changes independently of the UI contract. Stabilize test data or narrowly suppress the volatile region with a screenshot stylesheet.
A threshold hides a failure but the image still looks wrong The configured tolerance is too broad or the underlying difference is not understood. Review the diff, correct the source of variation, and tune the threshold only against representative changes.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Native snapshots or a hosted visual-testing workflow?

Playwright’s built-in screenshots are a practical starting point when your team wants checks in its existing test runner and is comfortable storing and reviewing reference images in the repository. Hosted tools may fit teams that want centralized baseline management or a shared review interface; they are not required for Playwright visual comparisons.

Approach What the cited documentation establishes What to evaluate for your team
Playwright Test Screenshot assertions and repository-managed reference images. Documentation. Whether code review and version control are a sufficient baseline and approval workflow.
Chromatic Playwright integration that uploads UI archives for cloud snapshots and review, with CI integration; its documentation states support for Playwright 1.38.0 and above. Confirm current compatibility. Documentation. Current compatibility, review workflow, browser and viewport needs, data handling, and current pricing.
Applitools A Playwright SDK with named visual checkpoints, match-level controls, and ignored regions. Documentation. How its controls and review process fit your tests, along with current pricing and data-handling terms.
Percy Visual testing integrated into development workflows; Percy identifies itself as part of BrowserStack. Product information. Baseline ownership, review, coverage, CI fit, current pricing, and data-handling terms.

These product pages establish capabilities, not a universal ranking or current price comparison. Choose based on where baselines live, how reviewers inspect and approve diffs, browser and viewport coverage, dynamic-content handling, CI integration, and your data requirements.

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server. One GET request can return an image or PDF; it can also remove cookie banners, newsletter popups, and chat widgets before capture. Bot checks, blank pages, and failed loads are never billed, and an MCP server lets AI agents take screenshots.

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://your-site.example/checkout -o shot.webp

See the ScreenshotNeo API documentation for request options. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Sign up for 1,000 free screenshots a month—no card required.

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

Does a screenshot assertion replace functional assertions?

No. Keep behavioral checks for what the app does and use the screenshot assertion to check how the rendered UI looks.

Can Playwright compare only one component instead of a whole page?

Yes. Call toHaveScreenshot() on a locator to constrain the visual check to that element.

Do I need a hosted visual-testing service to use Playwright screenshots?

No. Playwright Test includes screenshot comparison; hosted products are an optional workflow choice.

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.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.