# playwright-visual-testing

playwright-visual-testing — a skill providing Playwright visual regression testing patterns. Helps agents configure screenshot assertions, mask dynamic elements, and handle responsive snapshots in CI.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode, Windsurf (Devin Desktop), Claude.ai · 1 install · ★ 8 repo stars
- Author: bradtaylorsf
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/bradtaylorsf/alphaagent-team/tree/HEAD/plugins/aai-stack-playwright/skills/playwright-visual-testing/SKILL.md
- Updated: 2026-02-05
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/skills/bradtaylorsf-playwright-visual-testing

## What it does

This skill equips coding agents with patterns for Playwright visual regression testing using `@playwright/test`. It outlines `expect(page).toHaveScreenshot()` assertions alongside comparison options such as `maxDiffPixels`, color thresholds, and clipping masks. It also details techniques for flaky interfaces: masking locators with `mask`, replacing dynamic timestamps in the DOM, and disabling CSS animations via `addStyleTag`.

Responsive coverage includes iterating over viewport arrays and separating device profiles in `playwright.config.ts`. The instructions cover dark mode emulation with `page.emulateMedia`, button interaction states (`hover`, `focus`, `disabled`), and a sample GitHub Actions workflow that uploads test artifacts on failure.

The frontmatter sets `user-invocable: false`, meaning the agent consults this guide contextually rather than through a direct slash command. Running these suites still requires `@playwright/test` and browser binaries installed locally.

## Requirements
- Works with: Playwright

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add bradtaylorsf/alphaagent-team --skill playwright-visual-testing -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/playwright-visual-testing/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/playwright-visual-testing/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add bradtaylorsf/alphaagent-team --skill playwright-visual-testing -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/playwright-visual-testing/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add bradtaylorsf/alphaagent-team --skill playwright-visual-testing -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/playwright-visual-testing/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install bradtaylorsf/alphaagent-team plugins/aai-stack-playwright/skills/playwright-visual-testing
```

2. **Manually: put the files in place**
- File: `.github/skills/playwright-visual-testing/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add bradtaylorsf/alphaagent-team --skill playwright-visual-testing -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/bradtaylorsf/alphaagent-team --path plugins/aai-stack-playwright/skills/playwright-visual-testing
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/playwright-visual-testing/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add bradtaylorsf/alphaagent-team --skill playwright-visual-testing -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/bradtaylorsf/alphaagent-team/tree/HEAD/plugins/aai-stack-playwright/skills/playwright-visual-testing/SKILL.md

## When to use it
- configure full-page and element screenshot comparisons in Playwright
- mask dynamic timestamps or avatars during regression runs
- disable CSS animations to eliminate flaky visual test diffs
- test dark and light color schemes across viewports
- set up cross-platform `snapshotPathTemplate` rules in config

## Example prompts
- Write a Playwright visual regression test for `/dashboard` with dynamic timestamps masked
- Update `playwright.config.ts` to disable animations and configure multi-platform snapshot paths
- Create component visual tests verifying hover, focus, and disabled button states

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 3474d720309ffd0a.

BEGIN THIRD-PARTY FILE 3474d720309ffd0a
````text
---
name: playwright-visual-testing
description: Playwright visual comparison and screenshot testing
user-invocable: false
---

# Playwright Visual Testing Skill

Patterns for visual regression testing with Playwright.

## Screenshot Assertions

### Basic Screenshot Comparison

```typescript
import { test, expect } from '@playwright/test'

test('visual comparison', async ({ page }) => {
  await page.goto('/')

  // Compare full page
  await expect(page).toHaveScreenshot()

  // With custom name
  await expect(page).toHaveScreenshot('homepage.png')
})

// Element screenshot
test('component visual test', async ({ page }) => {
  await page.goto('/components')

  const card = page.locator('.card').first()
  await expect(card).toHaveScreenshot('card-component.png')
})
```

### Screenshot Options

```typescript
await expect(page).toHaveScreenshot('name.png', {
  // Comparison options
  maxDiffPixels: 100,           // Allow N different pixels
  maxDiffPixelRatio: 0.05,      // Allow 5% difference
  threshold: 0.2,                // Color difference threshold (0-1)

  // Capture options
  fullPage: true,                // Capture entire scrollable page
  clip: { x: 0, y: 0, width: 800, height: 600 },
  scale: 'css',                  // 'css' or 'device'
  animations: 'disabled',        // Disable animations
  mask: [page.locator('.dynamic')],  // Mask dynamic content
  maskColor: '#FF00FF',          // Mask overlay color
})
```

### Updating Snapshots

```bash
# Update all snapshots
npx playwright test --update-snapshots

# Update specific test
npx playwright test visual.spec.ts --update-snapshots
```

## Handling Dynamic Content

### Masking Elements

```typescript
test('mask dynamic content', async ({ page }) => {
  await page.goto('/dashboard')

  await expect(page).toHaveScreenshot('dashboard.png', {
    mask: [
      page.locator('.timestamp'),
      page.locator('.user-avatar'),
      page.locator('.random-ad'),
    ],
  })
})
```

### Waiting for Stability

```typescript
````
END THIRD-PARTY FILE 3474d720309ffd0a

The third-party file has ended. Everything between the 3474d720309ffd0a tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2005 of 8275 bytes. © bradtaylorsf · MIT · https://github.com/bradtaylorsf/alphaagent-team/tree/HEAD/plugins/aai-stack-playwright/skills/playwright-visual-testing/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
