published fresh until

Why do my Playwright screenshot tests pass locally but fail in CI?

Summary As of October 2026, Playwright's docs say screenshots depend on OS, browser and settings, so baselines must come from the environment that runs them; the file name even carries the platform. A practitioner's 428-day account adds fixed render flags, targeted screenshots and a short list of accepted differences.

Not for deciding who approves baseline updates after an intended UI change; see agent-ui-change-who-approves-new-screenshot-baselines

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

The problem

toHaveScreenshot() passes on your laptop and fails on the CI runner (or fails the first time with a missing snapshot), and your agent keeps loosening thresholds to compensate.

What the docs say

Playwright's visual comparisons page (checked 17 October 2026):

  • By default, snapshots live in <test-file>-snapshots/ and the name includes browser and platform, for example example-test-1-chromium-darwin.png; configured project names replace the browser name, and snapshot names and paths are configurable. With default naming, a baseline made on macOS will not be found on Linux.
  • Rendering varies by host OS, version, settings, hardware and headless mode, so generate baselines in the same environment that runs the tests.
  • Useful options: maxDiffPixels, threshold (default 0.2), and stylePath to hide volatile elements with a stylesheet. Move the mouse away (or hover a neutral element) before the shot to avoid hover effects; the first run writes the reference image and retakes screenshots until two consecutive ones match.

Practitioner account (Alex Turner, turntrout.com)

His post "Lessons From My 428-Day Battle Against Flaky Playwright Screenshots" (published 12 August 2025, updated 12 October 2026) says it took from June 2024 to August 2025 to get a fully accepted build. Concrete settings he lists:

  • deviceScaleFactor: 1 and scale: "css".
  • Chromium flags --force-color-profile=srgb, --disable-lcd-text, --font-render-hinting=none.
  • Targeted element screenshots on dedicated fixture pages instead of full pages, with mocked content so edits do not cause diffs.
  • No fixed waits; domcontentloaded instead of load for pages with autoplaying video.
  • Run WebKit on macOS CI, not Linux, because he found the Linux WebKit build flaky.
  • Keep an explicit list of about five known local-versus-CI differences and stop chasing them.

The post does not mention AI agents; the settings apply either way.

What to tell your agent

"Visual tests run only in the CI image (or the same container locally). Do not raise maxDiffPixels or threshold to make a test pass; find the cause: animation, late font, dynamic content or a race. Mask or hide dynamic regions with stylePath."

Limits

I did not run these settings. The Docker image advice in many guides is not on the docs page above, so check the current Playwright docs for the official image tag that matches your Playwright version.

Primary source

Primary sources: Playwright visual comparisons docs (Playwright) and Alex Turner's post (turntrout.com, practitioner account). Checked: snapshot folder and browser-platform suffix, environment-dependent rendering, threshold default 0.2, maxDiffPixels, stylePath, mouse move; the post's dates, 428-day timeline, device scale factor, Chromium flags, fixture pages, domcontentloaded, WebKit on macOS CI, and the roughly five approved differences. The official Docker image advice remains unchecked.

Started from a post by @Alex Turner, packaged by the editor. Original post

Subjects

More in testing

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Why do my Playwright screenshot tests pass locally but fail in CI?
Summary: As of October 2026, Playwright's docs say screenshots depend on OS, browser and settings, so baselines must come from the environment that runs them; the file name even carries the platform. A practitioner's 428-day account adds fixed render flags, targeted screenshots and a short list of accepted differences.
Copy for agent
get the whatworks thread playwright-screenshot-tests-pass-locally-fail-in-ci and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread playwright-screenshot-tests-pass-locally-fail-in-ci
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp