DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk6 min

How to Test Dark Mode with Playwright Screenshot Comparisons

Use Playwright’s color-scheme emulation and screenshot assertions to test dark mode reliably, review baselines, and diagnose visual diffs.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Playwright’s colorScheme: 'dark' emulation to put the page into dark mode, then use Playwright Test’s expect(page).toHaveScreenshot() to compare the rendered page with a reviewed reference image. Test dark and light states separately, keep the capture environment consistent, and treat any tolerance or baseline update as a deliberate review decision.

Set up a dark-mode screenshot test

Screenshot assertions are part of the Playwright Test runner. On its first run, toHaveScreenshot() creates a reference image; later runs compare the rendered output with that baseline. This example shows the documented API pattern, but has not been run against a particular application.

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

test('renders the home page in dark mode', async ({ page }) => {
  await page.emulateMedia({ colorScheme: 'dark' });
  await page.goto('/');
  await expect(page).toHaveScreenshot('home-dark.png');
});

Configure a working baseURL if the test uses a relative path such as /. Otherwise, pass the page’s full address to page.goto(). Set the emulated scheme before navigation when possible so the application can select its initial theme using prefers-color-scheme.

Choose where to set the color scheme

Playwright documents three ways to emulate a scheme. Choose the scope that matches your test organization:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
  • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
  • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
  • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents
Scope Example Best suited to
One page during a test await page.emulateMedia({ colorScheme: 'dark' }); A test that changes scheme or covers a specific page state.
Tests in a file or describe block test.use({ colorScheme: 'dark' }); A group of tests that should all run with the same scheme.
A browser context await browser.newContext({ colorScheme: 'dark' }); Tests that create their own context rather than using the standard fixture.
A Playwright Test project use: { colorScheme: 'dark' } A separately configured project in a test matrix.

The documented scheme values are light and dark. Choose the level appropriate to your suite and avoid setting contradictory values at multiple levels. See Playwright’s emulation guide for the configuration context.

Test light and dark as independent visual states

If your product supports both schemes, give each one an explicit test and snapshot name. Independent tests make it clear which state changed and avoid one test’s scheme switch leaking into another.

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

test('home page in light mode', async ({ page }) => {
  await page.emulateMedia({ colorScheme: 'light' });
  await page.goto('/');
  await expect(page).toHaveScreenshot('home-light.png');
});

test('home page in dark mode', async ({ page }) => {
  await page.emulateMedia({ colorScheme: 'dark' });
  await page.goto('/');
  await expect(page).toHaveScreenshot('home-dark.png');
});

You can also express the two states as separate Playwright Test projects, setting use: { colorScheme: 'light' } in one and use: { colorScheme: 'dark' } in the other. This is useful when the same suite should run under both settings. Keep snapshot names unambiguous so a diff identifies the intended scheme.

Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors

Make screenshots repeatable before tuning diffs

A visual assertion is useful only if an unexpected diff points to a meaningful change. Playwright notes that screenshot output can vary with host operating system, browser version, settings, hardware, power source, headless mode, and other factors. Its visual comparison documentation cautions that “Browser rendering can vary based on the host OS, version, settings, hardware, power source (battery vs. power adapter), headless mode, and other factors.”

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Generate and compare baselines with consistent operating system, browser version, and capture settings.
  • If you intentionally test more than one browser or platform, keep the expected images appropriate to those environments instead of treating every rendering difference as an application regression.
  • Wait for application content to be ready before asserting. The screenshot assertion itself waits until two consecutive page screenshots match before it compares the last capture with the expectation; that helps with transient rendering, but does not eliminate cross-environment differences.
  • Keep the tested viewport, device scale, and other relevant browser settings stable between baseline generation and comparison.

For details on snapshot behavior and maintenance, see Playwright’s visual comparisons guide.

Handle dynamic content without hiding dark-mode defects

Animations, clocks, rotating ads, or other changing elements can make snapshots noisy. Playwright’s stylePath option can apply a stylesheet while taking a screenshot, including to suppress volatile elements. Use it only for content outside the behavior under test. Hiding a component whose colors, visibility, or contrast matter in dark mode can conceal the very regression the test should catch.

Rank #3
Sale
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
  • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
  • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
  • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
  • Ultra-thin bezels: Maximize your viewing experience with thin bezels.

For example, a test-only stylesheet may hide a timestamp that changes on every render, while leaving the header, navigation, cards, and theme-dependent components visible. Review the affected elements whenever the stylesheet changes. See the snapshot assertion documentation for screenshot options.

Set comparison tolerance deliberately

Playwright’s screenshot comparison options include a perceived-color-difference threshold and limits on the number or proportion of differing pixels. The API reference documents a default YIQ color-difference threshold of 0.2; this is a configuration default, not a universal recommendation for dark-mode testing. Difference limits can be set in test or project configuration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Start with a strict comparison if the rendering environment is stable and the design is expected to be deterministic.
  • If harmless rendering noise remains, adjust the threshold or difference budget only after inspecting the diff and understanding its source.
  • Do not raise allowances simply to silence a failing test: a larger tolerance may also permit genuine color, contrast, or layout regressions.

Consult the snapshot assertion API reference for the options supported by your installed Playwright version.

Rank #4
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor
  • CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
  • SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
  • MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
  • KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
  • INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient

Review and update approved baselines

When a design change is intentional, regenerate the expected images with:

npx playwright test --update-snapshots

Inspect the resulting images and diffs, then commit only approved snapshots with the code change. Playwright recommends versioning and reviewing snapshots; do not refresh them reflexively just to turn a failed build green.

Troubleshoot common failures

Symptom Likely cause What to check
The page still looks light The app may not respond to prefers-color-scheme, may use a stored/manual theme setting, or may have received the emulation too late. Set the scheme before navigation, confirm the application’s theme behavior, and check whether a saved preference overrides the system preference.
The first run creates a snapshot instead of reporting a mismatch No reference image exists yet for that test and environment. Review the generated image as the proposed baseline, then retain it only if it represents the intended appearance.
A snapshot differs on another machine or CI runner Operating system, browser, rendering settings, hardware, power source, or headless mode may differ. Align capture environments or manage expectations separately for deliberate platform/browser coverage before changing tolerance.
Repeated failures show moving content A clock, animation, rotating ad, or other dynamic element changes between captures. Stabilize the content if possible; otherwise use stylePath narrowly for elements outside the tested behavior.
A test passes despite a visible small change The threshold or differing-pixel allowance may be too permissive. Inspect the diff and tighten the comparison settings to reflect the visual contract.
Snapshot update changes many files The environment or a shared style change may have altered broad rendering, or the update command may be applied too widely. Review each diff, confirm the intended project and environment, and avoid committing unexplained baseline changes.
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 rendered page capture outside a Playwright test, ScreenshotNeo provides a one-call screenshot API. It is not a replacement for a Playwright visual assertion or its versioned baselines; use it when you want a screenshot response without managing browser capture yourself. See the ScreenshotNeo API documentation.

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.
Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo accepts cookie/consent banners and removes 60+ known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks/CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify the page verdict and billing status. 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. More at ScreenshotNeo.

Sign up for 1,000 free screenshots a month, with no card required.

Frequently Asked Questions

How to test dark mode with Playwright?

Set the page’s emulated color scheme to dark and assert its expected appearance with Playwright Test’s toHaveScreenshot().

How do I compare screenshots in Playwright?

Use Playwright Test’s expect(page).toHaveScreenshot(); the first run establishes an expected image and later runs compare against it.

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 *

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.

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
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

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.