playwright-visual-testing
Add, repair, or review Playwright visual regression tests for browser-facing .NET apps, including screenshot baselines, Pixelmatch thresholds, deterministic rendering, and GitHub Actions artifacts. USE FOR: toHaveScreenshot, page.screenshot visual checks, Pixelmatch/pngjs comparison scripts, visual baseline updates, screenshot diff triage, or CI workflows for UI regression screenshots. DO NOT USE FOR: pure unit tests, accessibility audits, browser-debugging sessions, or frontend linting.
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 515
- Forks
- 41
01 前言 Front Matter
- name
- playwright-visual-testing
- description
- Add, repair, or review Playwright visual regression tests for browser-facing .NET apps, including screenshot baselines, Pixelmatch thresholds, deterministic rendering, and GitHub Actions artifacts. USE FOR: toHaveScreenshot, page.screenshot visual checks, Pixelmatch/pngjs comparison scripts, visual baseline updates, screenshot diff triage, or CI workflows for UI regression screenshots. DO NOT USE FOR: pure unit tests, accessibility audits, browser-debugging sessions, or frontend linting.
02 资源文件 2
- 参考文档manifest.json421 B
- 参考文档references/ci-and-snapshot-patterns.md8.8 KB
03 SKILL.md 正文
Playwright Visual Testing
Trigger On
- the user asks for pixel, screenshot, visual, or UI regression testing with Playwright
- a .NET repo needs visual baselines for ASP.NET Core, Blazor, WebAssembly, static pages, or generated frontend assets
- GitHub Actions should run Playwright screenshots and expose expected, actual, and diff artifacts
- tests fail with screenshot mismatches, noisy baselines, or unstable visual snapshots
Do Not Use For
- pure .NET unit or integration tests without a browser surface
- accessibility, SEO, PWA, or security-header audits; route those to
webhint - browser debugging or live DOM inspection; route that to
chrome-devtools-mcp - JavaScript, TypeScript, CSS, or HTML linting; route those to
biome,eslint,stylelint, orhtmlhint
Load References
- Read CI and snapshot patterns when adding a new visual test suite, wiring GitHub Actions, choosing between Playwright snapshots and a standalone Pixelmatch script, or stabilizing screenshot diffs.
Current Upstream Notes
- The August 2026 Playwright CI and visual-comparison docs still require browser dependencies to be installed explicitly in CI and warn that screenshot rendering varies by host OS, browser build, fonts, headless mode, and hardware. Generate and review baselines in the same environment used for comparison.
- The CI guide recommends against caching browser binaries by default: restoring them often costs as much as downloading, and OS dependencies still need an explicit install. If a runner must cache browsers, key it by the exact Playwright version and keep dependency installation in the job.
- Current CI examples use
actions/checkout@v6,actions/setup-node@v6, andactions/upload-artifact@v5; use a full checkout only when--only-changedneeds the pull-request base ref. - Keep Playwright parallel by default. Do not set
workers: 1merely because CI or screenshots are involved. Isolate test data and browser contexts, enablefullyParallelwhen tests are independent, and shard large suites across CI jobs. Reduce concurrency only for the smallest tests that destructively change the same external state. - Playwright
v1.62.1fixes TypeScript configuration resolution regressions, accessibility snapshots that dropped names or image-style actionable elements, and branded primitive arguments passed topage.evaluate(). Re-run config discovery, accessibility snapshots, and TypeScript compile checks before accepting new visual baselines. - Keep
--update-snapshotsas an intentional local review action. Pull-request CI should retain expected, actual, diff, trace, and report artifacts instead of silently accepting a new baseline.
Workflow
flowchart TD
A["Need visual regression coverage"] --> B{"Uses Playwright Test"}
B -->|"Yes"| C["Prefer expect(page).toHaveScreenshot"]
B -->|"No or custom compare needed"| D["Capture page.screenshot output"]
D --> E["Compare with pixelmatch and pngjs"]
C --> F["Stabilize viewport, data, animation, and volatile regions"]
E --> F
F --> G["Commit reviewed baselines"]
G --> H["Run in CI and upload reports or image diffs"]
H --> I["Triage expected, actual, and diff before changing thresholds"]
- Inspect the current browser-test surface:
- nearest
AGENTS.md package.json, lockfile, Playwright config, test folders, and CI workflows- how the app starts locally:
dotnet run, Aspire AppHost, static preview, or frontend dev server
- nearest
- Choose the comparison path deliberately:
- default to Playwright Test
expect(page).toHaveScreenshot()when the repo can use Playwright Test snapshots - use
page.screenshot()plus a standalone Pixelmatch script only when the repo needs article-style centralscreenshots/baseline,screenshots/actual, andscreenshots/difffolders, non-Playwright image inputs, or custom reporting outside Playwright Test
- default to Playwright Test
- Make screenshots deterministic before tuning thresholds:
- fix viewport, browser project, locale/time zone, color scheme, and device scale factor
- use stable test data and wait for the app-specific ready state
- disable animations or use Playwright screenshot options for animations
- mask or hide volatile regions such as ads, time, avatars, random IDs, spinners, and third-party iframes
- Keep baseline updates explicit:
- generate missing baselines once, review them, and commit them
- update intended Playwright snapshots with
npx playwright test --update-snapshots - do not auto-create or auto-update baselines in pull-request CI
- Wire CI for repeatability:
- use
npm ci, thennpx playwright install --with-deps, then the focused Playwright command - preserve Playwright's parallel workers; use
fullyParallelfor isolated tests and CI sharding for large suites - constrain only a narrow destructive shared-state collision, never the whole visual suite for generic stability
- optionally run
npx playwright test --only-changed=origin/$GITHUB_BASE_REFfirst on pull requests for faster feedback, but always follow it with the full suite because changed-test selection is heuristic - use the same OS, browser build, fonts, headless mode, and rendering environment that produced the committed baselines; an official Playwright container is useful when host drift keeps changing pixels
- upload the Playwright HTML report and
test-results/, or uploadscreenshots/baseline,screenshots/actual, andscreenshots/difffor a custom Pixelmatch flow
- use
- Triage failures from artifacts:
- inspect expected, actual, and diff images together
- classify the mismatch as intentional design change, rendering nondeterminism, app bug, or baseline drift
- fix nondeterminism before increasing
maxDiffPixels,maxDiffPixelRatio, or Pixelmatch mismatch thresholds
Deliver
- a Playwright visual-test path that matches the repo's existing package manager and test layout
- committed reviewed baseline images or a clear command to generate and review them
- deterministic screenshot controls for dynamic UI regions
- GitHub Actions report or diff artifacts that make failures reviewable
- a short note on whether the implementation uses built-in Playwright snapshots or a custom Pixelmatch comparison script
Validate
npm cinpx playwright install --with-depsnpx playwright testor the repo's focused visual-test scriptnpx playwright test --update-snapshotsonly when accepting intentional baseline changes- in CI changes, confirm artifact upload uses maintained GitHub Actions versions and runs on pull requests without requiring secrets
Common Pitfalls
- capturing screenshots before the UI is stable
- generating baselines on one OS and comparing them on another
- sharing one mutable browser context across tests
- masking too much of the page and removing the regression signal
- raising thresholds to hide animation, font, clock, or data nondeterminism
- forcing one CI worker instead of fixing data/context isolation or sharding the suite
- using a custom Pixelmatch script when Playwright's built-in screenshot assertion would give better trace, report, and snapshot integration
04 同仓库更多 Skills
xtwitter-scraper
Use XTwitterScraper when a .NET application needs typed access to Xquik's X automation REST API for tweet search, user lookup, posting workflows, extraction jobs, monitors, webhooks, or giveaway draws. USE FOR: integrating the XTwitterScraper NuGet package; reviewing Xquik API client usage; modeling API-key configuration, pagination, binary exports, raw responses, retries, and webhook/event flows in .NET. DO NOT USE FOR: unrelated stacks; direct browser automation; generic social-media strategy; or code that does not call Xquik. INVOKES: inspect the repository context, edit targeted files, and run relevant build, test, lint, or validation commands when changes are made.
sep
Use Sep for high-performance separated-value parsing and writing in .NET, including delimiter inference, explicit parser/writer options, and low-allocation row/column workflows. USE FOR: delimited data needs are performance-sensitive and allocation-aware; project needs explicit control over separator inference, escaping, trimming, and header behavior;. DO NOT USE FOR: unrelated stacks; generic tasks that do not need this specific guidance. INVOKES: inspect the repository context, edit targeted files, and run relevant build, test, lint, or validation commands when changes are made.
webgpu-threejs-tsl
Comprehensive guide for developing WebGPU-enabled Three.js applications using TSL (Three.js Shading Language). Covers WebGPU renderer setup, TSL syntax and node materials, compute shaders, post-processing effects, and WGSL integration. Use this skill when working with Three.js WebGPU, TSL shaders, node materials, or GPU compute in Three.js.
roslynk
Use Roslynk for semantic inspection and edits of *.cs, *.razor and *.cshtml solution files.
system-text-json-net11
Imperative guidance for the System.Text.Json APIs added in .NET 11: the built-in `JsonNamingPolicy.PascalCase` naming policy, and the strongly-typed generic `JsonSerializerOptions.GetTypeInfo` and `JsonSerializerOptions.TryGetTypeInfo` metadata accessors (generic overloads that return a typed `JsonTypeInfo`). USE ONLY when the user is targeting net11.0 or later and needs PascalCase JSON property or dictionary-key names without writing a custom naming policy, a strongly-typed generic `JsonTypeInfo` instead of the non-generic `JsonTypeInfo`, or a no-throw way to probe whether a type's serialization metadata is resolved. DO NOT USE when the target is earlier than net11.0, the requested behavior uses an established pre-net11 naming policy, or the user explicitly selected another JSON library.
process-api-net11
Provides guidance on the new System.Diagnostics.Process APIs introduced in .NET 11: Process.Run, Process.RunAndCaptureText, Process.StartAndForget, Process.ReadAllText/Bytes/Lines, KillOnParentExit, InheritedHandles, and StartDetached. USE FOR: starting, orchestrating, or capturing output from external processes in applications targeting net11.0 or later. DO NOT USE FOR: applications targeting .NET 10 or earlier, or basic pre-.NET 11 Process.Start usage without new APIs.