playwright-best-practices

Guides writing, debugging, and maintaining Playwright tests across E2E, component, and API scenarios.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Playwright test suites often suffer from flaky tests, brittle selectors, poor structure, and slow CI pipelines. This Skill provides organized, activity-based guidance covering the full Playwright testing lifecycle so you can write reliable tests, debug failures, and configure infrastructure correctly. ## Core Features & Use Cases - Activity-Based Reference Routing: A decision tree and lookup tables map your current task (writing E2E tests, fixing flaky tests, setting up CI/CD, mocking APIs) to the right reference file. - Comprehensive Coverage: Covers locators, assertions, Page Object Model, fixtures, authentication, network interception, WebSockets, mobile testing, accessibility, security testing, visual regression, Electron, browser extensions, and more. - Debugging & Infrastructure Guidance: Dedicated references for flaky test investigation, trace viewer usage, parallel sharding, GitHub Actions, GitLab CI, Docker, and performance optimization. - Use Case: Your tests pass locally but fail intermittently in CI with multiple workers. Consult the flaky tests and performance references to identify state leaks between workers and apply proper test isolation with fixtures. ## Quick Start Ask the AI to help you write a Playwright E2E test with proper locators and assertions, or to diagnose why a specific test is flaky in CI.

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 usually stem from race conditions, missing waits, or state leaks between tests. Use web-first assertions with auto-waiting instead of explicit timeouts, ensure test isolation with fixtures, and investigate failures with the trace viewer using npx playwright show-trace.

How do I structure Playwright tests with Page Object Model?

Page Object Model in Playwright encapsulates page locators and interactions into reusable classes, keeping tests readable and maintainable. The skill's references cover when to choose POM versus fixtures and how to structure test suites around them.

Should I use Page Object Model or fixtures in Playwright?

Playwright fixtures handle setup, teardown, and dependency injection, while POM organizes page interactions. They solve different problems and are often combined: fixtures can instantiate page objects so tests receive ready-to-use page instances.

How do I mock API responses in Playwright tests?

Playwright's route interception lets you mock API responses by intercepting network requests and fulfilling them with custom data. This covers REST and GraphQL endpoints, HAR recording and playback, and simulating network failures for error-state testing.

How do I run Playwright tests in CI/CD pipelines?

Playwright supports GitHub Actions, GitLab CI, Docker containers, and other providers with parallel sharding for faster runs. Configure retries, artifacts like traces and screenshots, and use test tags to run subsets such as @smoke tests on pull requests.

Why do Playwright tests fail only when running in parallel?

Parallel-only failures typically indicate shared state between workers, such as reused test accounts or database records. Isolate test data per worker using fixtures, and review the performance and flaky test references for worker-scoped isolation patterns.