agentleFS
RoninForgeRoninForge/roninforge-playwright/skills/playwright-visual-regression/SKILL.md

playwright-visual-regression

Skill0 starsChanged 7 months agoMITView on GitHub

Set up Playwright visual regression with toHaveScreenshot: mask volatile regions, animations: 'disabled', maxDiffPixels, the macOS-vs-Linux baseline trap (the #1 visual-regression gotcha), the CI workflow for diff review, and when to reach for Argos / Chromatic / Percy instead of the built-in.

  • Reads credentials
  • Installs packages

2 other projects use a version of this.

Adopted by

Most recently taken up by

  • Other versions2 projects use a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 2

    1. ella79/agentic-playwright-suite★ 8same name
    2. FutureAtoms/claude-skills-backup★ 1same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository3 other files it gives its agents.

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When you want to catch unintended UI changes - layout shifts, color regressions, missing elements - that pass functional tests.

    line 10
  2. Very specific:

    If the diff is intentional, developer runs RUN_VISUAL=1 npx playwright test --project=visual --update-snapshots on a Linux machine (or …

    line 86
  3. Very specific:

    Commit the linux PNGs only.

    line 95

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Set up Playwright Visual Regression

When to Use

When you want to catch unintended UI changes - layout shifts, color regressions, missing elements - that pass functional tests. Visual regression is a complement to web-first assertions, not a replacement.

Decision tree

  • Single-browser project, small surface, can pin CI to one OS → Built-in toHaveScreenshot() (this skill).
  • PR-attached visual diff approval flow, OSS-friendly → Argos (@argos-ci/playwright).
  • Storybook design system → Chromatic.
  • Need cross-OS rendering in the cloud (sidesteps macOS-vs-Linux) → Percy.

This skill covers the built-in flow. For the third-party services, follow their docs.

Step 1: write the visual test

// tests/visual/home.visual.spec.ts
import { test, expect } from "@playwright/test";

test("home page", async ({ page }) => {
  await page.goto("/");
  // Always wait for the page to be visually stable BEFORE the screenshot.
  await expect(page.getByRole("heading", { name: "Welcome" })).toBeVisible();

  await expect(page).toHaveScreenshot("home.png", {
    fullPage: true,
    mask: [
      page.locator("[data-testid='timestamp']"),
      page.locator(".live-counter"),
      page.locator(".user-avatar"),
    ],
    animations: "disabled",
    maxDiffPixels: 100,
  });
});

Key options:

  • mask - locators whose pixels are replaced with magenta blocks before comparison. Use for volatile regions (timestamps, counters, avatars, ads).
  • animations: "disabled" - freezes CSS animations and the text-input caret. The default in modern Playwright versions; explicit is fine.
  • maxDiffPixels - absolute pixel-count tolerance. Unset by default.
  • threshold - 0 to 1, YIQ pixelmatch sensitivity. Default 0.2. Lower = stricter.
  • stylePath - inject CSS before capture (useful to hide volatile elements without DOM-level masking).
  • fullPage - capture beyond the viewport.

Step 2: a dedicated visual project (load-bearing)

This is where the macOS-vs-Linux gotcha lives. Snapshot baselines from your dev macOS will not match CI Linux. Solve it with a dedicated project that runs only on Linux, with baselines committed only from CI artifacts.

// playwright.config.ts (excerpt)
import { defineConfig, devices } from "@playwright/test";

export default defineConfig({
  projects: [
    // ... existing functional projects ...
    {
      name: "visual",
      testMatch: /.*\.visual\.spec\.ts/,
      use: { ...devices["Desktop Chrome"] },
      // Only run when we explicitly opt in - avoids cross-OS baseline drift in dev.
      // Two equivalent ways to express "skip unless RUN_VISUAL is set":
      //   testIgnore: process.env.RUN_VISUAL ? undefined : ['**'],   // official option
      //   grep: process.env.RUN_VISUAL ? undefined : /__never__/,    // sentinel pattern
      testIgnore: process.env.RUN_VISUAL ? undefined : ["**"],
    },
  ],
});

Locally: RUN_VISUAL=1 npx playwright test --project=visual. CI: set RUN_VISUAL=1 only on Linux runners.

Step 3: the baseline workflow

  1. Developer pushes a UI change.
  2. CI runs npx playwright test --project=visual and fails on diff.
  3. Developer opens the HTML report (playwright-report/index.html) or the trace, reviews the diff (expected / actual / diff side-by-side).
  4. If the diff is intentional, developer runs RUN_VISUAL=1 npx playwright test --project=visual --update-snapshots on a Linux machine (or downloads the CI artifact and commits the new PNG).
  5. PR approver re-runs CI; baselines now match.

Never auto-update snapshots in CI. That defeats the purpose.

Step 4: snapshot file layout

Snapshots go to <testfile>-snapshots/<name>-<projectName>-<platform>.png. Example: tests/visual/home.visual.spec.ts-snapshots/home-visual-linux.png.

Commit the linux PNGs only. Add to .gitignore:

# Reject non-Linux snapshots (commit only what CI produces)
**/*-snapshots/*-darwin.png
**/*-snapshots/*-darwin-arm64.png
**/*-snapshots/*-win32.png

Step 5: CI workflow snippet

# .github/workflows/visual.yml
name: visual
on:
  pull_request:
    paths:
      - "src/**"
      - "tests/visual/**"
      - "playwright.config.ts"
jobs:
  visual:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: 20, cache: pnpm }
      - run: pnpm install --frozen-lockfile
      - run: npx playwright install --with-deps chromium
      - run: RUN_VISUAL=1 npx playwright test --project=visual --reporter=html
        env:
          RUN_VISUAL: "1"
      - if: failure()
        uses: actions/upload-artifact@v4
        with:
          name: playwright-visual-report
          path: playwright-report/
          retention-days: 14

Common mistakes to refuse

  • Committing macOS baselines - they will not match CI Linux. Always regenerate from a Linux runner.
  • Forgetting mask: for volatile regions - timestamps, counters, avatars cause every run to fail. Mask them out.
  • Screenshot taken before the page is stable - flake. Always assert the page reached its final state first (await expect(...).toBeVisible()).
  • maxDiffPixels: 1000 to "stop the flake" - hides real regressions. Lower the tolerance, fix the source of variance.
  • threshold: 1 ditto - that's "anything passes."
  • fullPage: true on a long scrolling page with lazy-loaded content - bottom of the page is unloaded when the screenshot is taken. Either scroll-and-wait first, or screenshot the visible region only.
  • Auto-update in CI - defeats the purpose. Only update locally (or by downloading the CI artifact) after a human eyeballs the diff.

When to reach for a third-party service

The built-in is good when:

  • You have one OS (Linux CI) and one browser project for visuals.
  • The team can review diffs in the HTML report.
  • You don't need a PR-attached approval flow.

Reach for Argos when you want a polished review UI free; Chromatic when you have a Storybook design system; Percy when you need cross-OS rendering in the cloud (sidesteps the baseline-OS problem entirely).

Reference

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.