playwright-snapshots
БесплатноБез исполняемых скриптовНе проверенUse when a project wants self-hosted visual regression tests in Playwright with no external service: toHaveScreenshot assertions, masks, clips and thresholds…
от testland★ 18 звёзд на GitHubОб этом скилле
playwright-snapshots
Overview
Playwright ships first-party visual regression assertions through
expect(page).toHaveScreenshot() (and the per-locator
expect(locator).toHaveScreenshot()). Snapshots are stored in the repo
under per-test, per-browser, per-OS PNG files; comparison happens
locally and the test fails when the diff exceeds the configured
threshold (playwright-snapshots).
This is the self-hosted option - no external service, no per-snapshot billing, but also no hosted UI for review (diffs are reviewed locally or via CI artifact uploads).
When to use
- The project already uses
@playwright/test. - The team prefers visual baselines committed to the repo (and reviewed in PR diffs) over a hosted UI.
- Coverage is page-driven (full pages, full viewports) rather than
story-driven (in which case
chromatic-visual-regression-testingmay be a better fit). - Snapshot determinism is high enough that pixel diffs are signal, not noise. If the page has chronic instability (animated SVGs, ads, A/B experiments), invest in masking before adopting.
Authoring
Page-level assertion
import { test, expect } from '@playwright/test';
test('homepage visual', async ({ page }) => {
await page.goto('/');
await expect(page).toHaveScreenshot();
});
The first run generates the baseline PNG; subsequent runs compare against it (playwright-snapshots).
Locator-level assertion
test('header visual', async ({ page }) => {
await page.goto('/');
await expect(page.locator('header')).toHaveScreenshot('header.png');
});
A locator-level snapshot is preferred when the surrounding page has unrelated dynamic content (e.g. a ticker, a chat widget) - it scopes the comparison and avoids false positives.
toHaveScreenshot() options
Per the PageAssertions API:
| Option | Effect |
|---|---|
animations |
"disabled" (default) fast-forwards finite animations and cancels infinite ones; "allow" keeps them. |
caret |
"hide" (default) removes the text cursor; "initial" preserves caret blinking. |
clip |
Rectangular area {x, y, width, height} to capture. |
fullPage |
Capture the full scrollable page rather than just the viewport. |
mask |
Array of locators whose elements are overlaid with a solid color (content hidden). |
maskColor |
CSS color for the mask overlay; defaults to pink (#FF00FF). |
maxDiffPixels |
Maximum absolute number of differing pixels allowed. |
maxDiffPixelRatio |
Maximum proportion (0 - 1) of differing pixels relative to total. |
omitBackground |
Hide the white background for transparent capture (PNG only). |
scale |
"css" (default; one image px per CSS px) or "device" for HiDPI capture. |
stylePath |
Path to a CSS file applied during capture to hide dynamic elements. |
threshold |
Acceptable per-pixel color difference in YIQ space (0 - 1); default 0.2. |
timeout |
Milliseconds to retry the assertion before failing. |
Common patterns:
// Mask a chat widget that animates
await expect(page).toHaveScreenshot({
mask: [page.locator('#intercom-container')],
});
// Allow up to 50 differing pixels (anti-aliasing tolerance)
await expect(page).toHaveScreenshot({ maxDiffPixels: 50 });
// Clip to a known-stable region of an otherwise-noisy page
await expect(page).toHaveScreenshot({
clip: { x: 0, y: 0, width: 1280, height: 400 },
});
Snapshot directory layout
Playwright stores baselines in a sibling directory of the test file (playwright-snapshots):
tests/
homepage.spec.ts
homepage.spec.ts-snapshots/
homepage-visual-1-chromium-darwin.png
homepage-visual-1-chromium-linux.png
homepage-visual-1-firefox-darwin.png
...
Naming: [test-name]-[index]-[browser]-[platform].png (playwright-snapshots).
This means baselines are platform-specific. Anti-aliasing, font
rendering, and emoji bitmaps differ between macOS, Linux, and Windows;
treat the platform suffix as load-bearing. The CI runner must match
the platform whose baselines are committed (typically linux).
Project-wide configuration
Set defaults in playwright.config.ts so individual tests stay clean
(playwright-snapshots):
import { defineCon
Установить playwright-snapshots в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл playwright-snapshots?
Use when a project wants self-hosted visual regression tests in Playwright with no external service: toHaveScreenshot assertions, masks, clips and thresholds, per-OS and per-browser snapshot folders, --update-snapshots, and a viewport matrix across responsive breakpoints.
Как установить скилл playwright-snapshots?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл playwright-snapshots запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic