playwright-best-practices

Guides writing, debugging, and maintaining Playwright tests in TypeScript across E2E, component, and API testing.

Updated Mar 31, 2026
One-click install
npx skills add https://github.com/sonth87/Redprint --skill playwright-best-practices-sonth87
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: playwright-best-practices
Source: https://github.com/sonth87/Redprint/tree/main/.agents/skills/playwright-best-practices
Command: npx skills add https://github.com/sonth87/Redprint --skill playwright-best-practices-sonth87

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing reliable Playwright tests requires knowing dozens of patterns for locators, waiting, fixtures, mocking, and debugging, and mistakes lead to flaky suites and slow CI pipelines. This Skill routes the AI to the right reference guide for your current testing activity so you get focused, correct guidance without loading everything at once. ## Core Features & Use Cases - Activity-Based References: Over 30 topic guides covering locators, assertions, Page Object Model, fixtures, flaky test diagnosis, CI/CD, network interception, accessibility, mobile, Electron, and browser extension testing. - Debugging & Flakiness Workflows: Dedicated guidance for trace viewer usage, race conditions, timeout issues, and test isolation problems. - Use Case: When you ask to fix a flaky login test, the Skill directs the AI to the flaky-tests, debugging, and assertions references so the fix uses auto-waiting and robust locators instead of arbitrary timeouts. ## Quick Start Ask the AI to write or fix a Playwright test, such as adding accessibility checks to your checkout flow, and it will apply the relevant best practices automatically.

Frequently Asked Questions about playwright-best-practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix flaky Playwright tests?▼

Flaky Playwright tests are usually caused by race conditions, explicit waits, or state leakage between tests. Replace waitForTimeout with web-first assertions and auto-waiting, ensure test isolation through fixtures, and use the trace viewer to diagnose timing issues.

How to write robust locators in Playwright?▼

Prefer user-facing locators like getByRole, getByLabel, and getByText over CSS or XPath selectors, since they reflect how users interact with the page. Avoid brittle selectors tied to implementation details that break on minor UI changes.

Does Playwright support accessibility testing with axe-core?▼

Yes, Playwright integrates with @axe-core/playwright to run automated accessibility scans. You can analyze full pages or scoped regions, filter by WCAG tags, and build a reusable fixture that fails tests when violations are detected.

Can Playwright test browser extensions and Electron apps?▼

Playwright supports both, with constraints. Browser extensions require Chromium launched with a persistent context in headed mode, while Electron apps are automated by connecting to the Electron main process and accessing renderer windows.

Why do Playwright tests fail only in CI or parallel runs?▼

Failures limited to CI or parallel execution typically indicate shared state, resource contention, or timing differences under load. Isolate test data per worker, avoid global mutable state, and use proper waiting instead of fixed timeouts.

When should I use Page Object Model in Playwright?▼

Use Page Object Model when multiple tests interact with the same pages or components, to centralize locators and actions. It reduces duplication and makes tests resilient to UI changes, but adds overhead for very small suites.