Playwright
Add visual regression assertions to your Playwright tests.
Prerequisites
Section titled “Prerequisites”npm install --save-dev @pxdiff/playwrightCreate a global setup file, a test fixture, and reference both in your Playwright config:
import { pxdiffSetup } from "@pxdiff/playwright/setup";
export default function setup(): void { pxdiffSetup();}import { test as base } from "@playwright/test";import { createPxdiffFixture } from "@pxdiff/playwright";
export const test = base.extend( createPxdiffFixture({ suite: "my-app", }));
export { expect } from "@playwright/test";import { defineConfig } from "@playwright/test";
export default defineConfig({ globalSetup: "./global-setup.ts",});Write Tests
Section titled “Write Tests”import { test, expect } from "./fixtures";
test("homepage", async ({ page }) => { await page.goto("/"); await expect(page).toMatchPxdiff("homepage");});Local Development
Section titled “Local Development”One-time setup — authenticate and link your project:
pxdiff loginpxdiff project set myorg/myprojectRun your tests with pxdiff:
pxdiff local -- npx playwright testCreate an API key for your project and set it as a repository secret.
name: Visual Regressionon: pull_request
jobs: visual: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: 24 cache: npm
- run: npm ci - run: npx playwright install --with-deps chromium
- name: Visual Regression run: pxdiff run -- npx playwright test env: PXDIFF_API_KEY: ${{ secrets.PXDIFF_API_KEY }}pxdiff run creates a GitHub check run, groups all screenshots into one session, and reports results back to the PR.
Cross-platform consistency
Section titled “Cross-platform consistency”If your screenshots differ between macOS and Linux due to font rendering, use --docker to run tests in a consistent container:
pxdiff run --docker -- npx playwright testpxdiff local --docker -- npx playwright testSee the Docker guide for details.
See the Playwright plugin reference for all matcher options.