agentleFS
salmandevsalmandev/everything-gemini/skills/playwright-visual-regression/SKILL.md

playwright-visual-regression

Skill3 starsChanged 48 days agoApache-2.0View on GitHub

Implements automated visual regression testing, pixelmatch snapshot diffing, cross-browser viewport matrices, dynamic element masking, and containerized baseline stability using Playwright.

  • Reads credentials

2 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    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. Very specific:

    Deterministic Environment: Always generate reference snapshots inside the same containerized Linux environment …

    line 15
  2. Distinctive:

    Wait for Font & Network Idle: Ensure web fonts and critical API payloads are loaded before capturing snapshots.

    line 17
  3. Very specific:

    Strict Diff Thresholds: Use maxDiffPixelRatio: 0.01 (1% tolerance) to balance anti-aliasing tolerance against regression detection.

    line 18
  4. Distinctive:

    Run snapshots inside the official Playwright Docker container to prevent cross-platform font rendering diffs:

    line 101

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 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

Playwright Visual Regression Testing & Snapshot Diffing

This skill provides production standards for catching unintended UI regressions, CSS layout shifts, and visual anomalies across viewports using Playwright's native screenshot comparison engine.


⚡ The Golden Rules of Visual Testing

  1. Deterministic Environment: Always generate reference snapshots inside the same containerized Linux environment (mcr.microsoft.com/playwright) to avoid font rendering divergence between macOS and CI runners.
  2. Mask Dynamic Elements: Mask timestamps, avatars, animations, and non-deterministic text using Playwright's mask option.
  3. Wait for Font & Network Idle: Ensure web fonts and critical API payloads are loaded before capturing snapshots.
  4. Strict Diff Thresholds: Use maxDiffPixelRatio: 0.01 (1% tolerance) to balance anti-aliasing tolerance against regression detection.

🏗️ Production Playwright Configuration (playwright.config.ts)

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

export default defineConfig({
  testDir: './tests/visual',
  snapshotPathTemplate: '{testDir}/__snapshots__/{testFilePath}/{arg}{ext}',
  expect: {
    toHaveScreenshot: {
      maxDiffPixelRatio: 0.01,
      animations: 'disabled',
      threshold: 0.2, // Pixel color sensitivity (0.0 to 1.0)
    },
  },
  use: {
    baseURL: process.env.BASE_URL || 'http://localhost:3000',
    trace: 'on-first-retry',
    screenshot: 'only-on-failure',
  },
  projects: [
    {
      name: 'Desktop Chrome',
      use: { ...devices['Desktop Chrome'], viewport: { width: 1440, height: 900 } },
    },
    {
      name: 'Mobile Safari',
      use: { ...devices['iPhone 14'], viewport: { width: 390, height: 844 } },
    },
    {
      name: 'Tablet iPad',
      use: { ...devices['iPad Pro 11'], viewport: { width: 834, height: 1194 } },
    },
  ],
});

🧪 Visual Test Implementation (tests/visual/dashboard.spec.ts)

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

test.describe('Dashboard Visual Regression Suite', () => {
  test.beforeEach(async ({ page }) => {
    // Navigate and stabilize network
    await page.goto('/dashboard', { waitUntil: 'networkidle' });
    
    // Wait for custom web fonts to be completely rendered
    await page.evaluate(() => document.fonts.ready);
  });

  test('full dashboard page layout matches baseline', async ({ page }) => {
    // Dynamic locators that vary between test runs
    const dynamicTimestamp = page.locator('[data-testid="last-sync-time"]');
    const userAvatar = page.locator('[data-testid="user-avatar"]');

    await expect(page).toHaveScreenshot('dashboard-main-view.png', {
      fullPage: true,
      mask: [dynamicTimestamp, userAvatar],
      maskColor: '#1e293b',
    });
  });

  test('component-level snapshot for modal dialog', async ({ page }) => {
    await page.click('[data-testid="open-settings-modal"]');
    const modal = page.locator('[role="dialog"]');
    
    await expect(modal).toBeVisible();
    await expect(modal).toHaveScreenshot('settings-modal.png');
  });
});

🐳 Containerized Snapshot Workflow (CI Stability)

Run snapshots inside the official Playwright Docker container to prevent cross-platform font rendering diffs:

# 1. Update baseline snapshots inside Docker container
docker run --rm --network host -v $(pwd):/work/ -w /work/ \
  mcr.microsoft.com/playwright:v1.45.0-jammy \
  npx playwright test --update-snapshots

# 2. Run visual validation in CI
docker run --rm --network host -v $(pwd):/work/ -w /work/ \
  mcr.microsoft.com/playwright:v1.45.0-jammy \
  npx playwright test

📋 Checklist & Anti-Patterns

Category❌ Anti-Pattern✅ Production Best Practice
AnimationTaking snapshots with active CSS transitionsSet animations: 'disabled' in config
FlakinessRelying on page.waitForTimeout(3000)Wait on networkidle, document.fonts.ready, and locator visibility
ScopeCapturing entire page for minor widget changesUse element locators: expect(locator).toHaveScreenshot()
OS MismatchCommitting macOS snapshots to run in Ubuntu CIGenerate reference snapshots with Docker container

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.