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 desk4 min

How to Set Up Screenshot Comparison for a React Website with Playwright

Use Playwright Test’s built-in screenshot assertion to create visual baselines for a React website and catch changes without noisy comparisons.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Playwright Test’s built-in expect(page).toHaveScreenshot() assertion to compare a React website against a visual baseline. The first run creates the reference image; later runs compare new captures with it. The most important setup decision is keeping baseline creation and comparison in a consistent browser and operating-system environment.

Install Playwright Test and point it at your React app

Playwright’s screenshot assertion operates on a browser page, so it tests the React app as rendered in the browser; the documented workflow does not require a React-specific Playwright package. Your app must be available at a test URL, with any needed startup, test data, authentication, and route setup supplied by your project.

As an Amazon Associate I earn from qualifying purchases.

Install the Playwright Test runner if it is not already part of the project:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
npm init playwright@latest

Follow the setup prompts for your project. Then add a test such as tests/visual.spec.ts, adjusting the URL, viewport, and state setup for your app:

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

test('home page matches its visual baseline', async ({ page }) => {
  await page.setViewportSize({ width: 1280, height: 800 });
  await page.goto('http://127.0.0.1:3000');

  // Add deterministic setup here: sign in or seed state if needed,
  // dismiss or configure banners, and wait for the intended UI state.
  await expect(page).toHaveScreenshot('home.png');
});

The URL and viewport are example choices, not Playwright requirements. Use your app’s local or preview URL, choose a viewport you intend to protect, and bring the page into the exact state you want to test.

Run the test and manage visual baselines

Create the initial reference

Run the test with the Playwright Test runner. On the first run, the expected screenshot does not yet exist, so Playwright reports that and writes the captured image as a baseline. Snapshot files are stored in a directory associated with the test file.

Review and commit baselines

Commit the snapshot directory to version control and review image changes alongside code changes. When a UI change is intentional, regenerate the reference with:

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

Inspect the new images before accepting them. Updating snapshots changes what future runs treat as expected; it should not be used to make an unexplained failure disappear. Playwright’s screenshot assertion waits until two consecutive screenshots are identical before comparing the last capture with the expected image.

Reduce noisy failures without hiding regressions

Keep the rendering environment consistent

Rendering can vary with the host operating system, browser version, settings, hardware, power conditions, and headless mode. Generate baselines and compare them in a consistent environment where possible. In CI, keep the browser build and rendering settings aligned with the environment used to create the references.

Set an evidence-based tolerance

Use maxDiffPixels to allow a defined number of differing pixels, or threshold to adjust the acceptable per-pixel color difference. For example, a project might configure a global pixel allowance like this:

import { defineConfig } from '@playwright/test';

export default defineConfig({
  expect: {
    toHaveScreenshot: {
      maxDiffPixels: 100,
    },
  },
});

The value 100 is illustrative, not a universal recommendation. Choose tolerance after inspecting the noise your pages actually produce. A looser comparison can also conceal a meaningful layout change.

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.

Capture only the relevant, stable area

If unrelated content changes frequently, use a locator’s screenshot assertion to compare a stable element rather than the whole page. Page and element screenshot assertions are both available. Keep the capture scope aligned with the behavior you want to protect: hiding a volatile region is useful only when its appearance is not itself under test.

When an element or page includes genuinely volatile content, Playwright’s stylePath option can apply a stylesheet to improve determinism. Avoid styling away content whose visual behavior matters to the test.

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

Diagnose a failed comparison

  • Check the expected, actual, and diff images first. Identify whether the difference is a product regression, an intended design change, or environment drift.
  • Check the page state. Confirm that the test reached the intended route and state, and that authentication, seeded data, banners, and other setup are deterministic.
  • Check the rendering environment. Compare browser version, operating system, viewport, and relevant settings with those used to create the baseline.
  • Check the capture scope. If the diff comes from unrelated dynamic content, consider a stable element or a deliberately scoped page capture.
  • Adjust tolerance only for understood noise. If pixels differ because of a known, acceptable rendering variation, tune maxDiffPixels or threshold carefully. Do not increase tolerance before understanding the diff.
  • Update snapshots only for intentional changes. Regenerate and review references when the design change is expected, then commit the reviewed images with the code change.

Use the screenshot assertion for visual comparisons

For page screenshots, use await expect(page).toHaveScreenshot(). Playwright’s snapshot documentation directs screenshot comparisons to this assertion rather than taking a screenshot buffer and passing it to toMatchSnapshot().

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server. Its one-request API returns a screenshot or PDF, but it is not a replacement for Playwright’s baseline assertions when you need automated regression comparisons inside your test suite.

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

For a quick capture from a React app URL, use this cURL example; replace the target URL with your local or deployed app URL:

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 and consent banners, newsletter popups, and chat widgets before capture; those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers indicate the page verdict and billing status. Its MCP server exposes screenshot, page-info, and PDF-capture tools for AI agents. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.

Sign up for ScreenshotNeo’s free plan to try 1,000 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.

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.

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. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver 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.