| name | playwright-best-practices |
| description | Use when writing Playwright tests, fixing flaky tests, debugging failures, implementing Page Object Model, configuring CI/CD, optimizing performance, mocking APIs, handling authentication or OAuth, testing accessibility (axe-core), file uploads/downloads, date/time mocking, WebSockets, geolocation, permissions, multi-tab/popup flows, mobile/responsive layouts, touch gestures, GraphQL, error handling, offline mode, multi-user collaboration, third-party services (payments, email verification), console error monitoring, global setup/teardown, test annotations (skip, fixme, slow), test tags (@smoke, @fast, @critical, filtering with --grep), project dependencies, security testing (XSS, CSRF, auth), performance budgets (Web Vitals, Lighthouse), iframes, component testing, canvas/WebGL, service workers/PWA, test coverage, i18n/localization, Electron apps, or browser extension testing. Covers E2E, component, API, visual, accessibility, security, Electron, and extension testing. |
| license | MIT |
| metadata | {"author":"currents.dev","version":"1.1"} |
Playwright Best Practices
This skill provides comprehensive guidance for all aspects of Playwright test development, from writing new tests to debugging and maintaining existing test suites.
Activity-Based Reference Guide
Consult these references based on what you're doing:
Writing New Tests
When to use: Creating new test files, writing test cases, implementing test scenarios
| Activity | Reference Files |
|---|
| Writing E2E tests | test-suite-structure.md, locators.md, assertions-waiting.md |
| Writing component tests | component-testing.md, test-suite-structure.md |
| Writing API tests | api-testing.md, test-suite-structure.md |
| Writing GraphQL tests | graphql-testing.md, api-testing.md |
| Writing visual regression tests | visual-regression.md, canvas-webgl.md |
| Structuring test code with POM | page-object-model.md, test-suite-structure.md |
| Setting up test data/fixtures | fixtures-hooks.md, test-data.md |
| Handling authentication | authentication.md, authentication-flows.md |
| Testing date/time features | clock-mocking.md |
| Testing file upload/download | file-operations.md, file-upload-download.md |
| Testing forms/validation | forms-validation.md |
| Testing drag and drop | drag-drop.md |
| Testing accessibility | accessibility.md |
| Testing security (XSS, CSRF) | security-testing.md |
| Using test annotations | annotations.md |
| Using test tags | test-tags.md |
| Testing iframes | iframes.md |
| Testing canvas/WebGL | canvas-webgl.md |
| Internationalization (i18n) | i18n.md |
| Testing Electron apps | electron.md |
| Testing browser extensions | browser-extensions.md |
Mobile & Responsive Testing
When to use: Testing mobile devices, touch interactions, responsive layouts
Real-Time & Browser APIs
When to use: Testing WebSockets, geolocation, permissions, multi-tab flows
Debugging & Troubleshooting
When to use: Test failures, element not found, timeouts, unexpected behavior
| Activity | Reference Files |
|---|
| Debugging test failures | debugging.md, assertions-waiting.md |
| Fixing flaky tests | flaky-tests.md, debugging.md, assertions-waiting.md |
| Debugging flaky parallel runs | flaky-tests.md, performance.md, fixtures-hooks.md |
| Ensuring test isolation / avoiding state leak | flaky-tests.md, fixtures-hooks.md, performance.md |
| Fixing selector issues | locators.md, debugging.md |
| Investigating timeout issues | assertions-waiting.md, debugging.md |
| Using trace viewer | debugging.md |
| Debugging race conditions | flaky-tests.md, debugging.md, assertions-waiting.md |
| Debugging console/JS errors | console-errors.md, debugging.md |
Error & Edge Case Testing
When to use: Testing error states, offline mode, network failures, validation
Multi-User & Collaboration Testing
When to use: Testing features involving multiple users, roles, or real-time collaboration
Architecture Decisions
When to use: Choosing test patterns, deciding between approaches, planning test architecture
Framework-Specific Testing
When to use: Testing React, Angular, Vue, or Next.js applications
Refactoring & Maintenance
When to use: Improving existing tests, code review, reducing duplication
Infrastructure & Configuration
When to use: Setting up projects, configuring CI/CD, optimizing performance
Advanced Patterns
When to use: Complex scenarios, API mocking, network interception
Quick Decision Tree
What are you doing?
ā
āā Writing a new test?
ā āā E2E test ā core/test-suite-structure.md, core/locators.md, core/assertions-waiting.md
ā āā Component test ā testing-patterns/component-testing.md
ā āā API test ā testing-patterns/api-testing.md, core/test-suite-structure.md
ā āā GraphQL test ā testing-patterns/graphql-testing.md
ā āā Visual regression ā testing-patterns/visual-regression.md
ā āā Visual/canvas test ā testing-patterns/canvas-webgl.md, core/test-suite-structure.md
ā āā Accessibility test ā testing-patterns/accessibility.md
ā āā Mobile/responsive test ā advanced/mobile-testing.md
ā āā i18n/locale test ā testing-patterns/i18n.md
ā āā Electron app test ā testing-patterns/electron.md
ā āā Browser extension test ā testing-patterns/browser-extensions.md
ā āā Multi-user test ā advanced/multi-user.md
ā āā Form validation test ā testing-patterns/forms-validation.md
ā āā Drag and drop test ā testing-patterns/drag-drop.md
ā
āā Testing specific features?
ā āā File upload/download ā testing-patterns/file-operations.md, testing-patterns/file-upload-download.md
ā āā Date/time dependent ā advanced/clock-mocking.md
ā āā WebSocket/real-time ā browser-apis/websockets.md
ā āā Geolocation/permissions ā browser-apis/browser-apis.md
ā āā OAuth/SSO mocking ā advanced/third-party.md, advanced/multi-context.md
ā āā Payments/email/SMS ā advanced/third-party.md
ā āā iFrames ā browser-apis/iframes.md
ā āā Canvas/WebGL/charts ā testing-patterns/canvas-webgl.md
ā āā Service workers/PWA ā browser-apis/service-workers.md
ā āā i18n/localization ā testing-patterns/i18n.md
ā āā Security (XSS, CSRF) ā testing-patterns/security-testing.md
ā āā Performance/Web Vitals ā testing-patterns/performance-testing.md
ā
āā Architecture decisions?
ā āā POM vs fixtures ā architecture/pom-vs-fixtures.md
ā āā Test type selection ā architecture/test-architecture.md
ā āā Mock vs real services ā architecture/when-to-mock.md
ā āā Test suite structure ā core/test-suite-structure.md
ā
āā Framework-specific testing?
ā āā React app ā frameworks/react.md
ā āā Angular app ā frameworks/angular.md
ā āā Vue/Nuxt app ā frameworks/vue.md
ā āā Next.js app ā frameworks/nextjs.md
ā
āā Authentication testing?
ā āā Basic auth patterns ā advanced/authentication.md
ā āā Complex flows (MFA, reset) ā advanced/authentication-flows.md
ā
āā Test is failing/flaky?
ā āā Flaky test investigation ā debugging/flaky-tests.md
ā āā Element not found ā core/locators.md, debugging/debugging.md
ā āā Timeout issues ā core/assertions-waiting.md, debugging/debugging.md
ā āā Race conditions ā debugging/flaky-tests.md, debugging/debugging.md
ā āā Flaky only with multiple workers ā debugging/flaky-tests.md, infrastructure-ci-cd/performance.md
ā āā State leak / isolation ā debugging/flaky-tests.md, core/fixtures-hooks.md
ā āā Console/JS errors ā debugging/console-errors.md, debugging/debugging.md
ā āā General debugging ā debugging/debugging.md
ā
āā Testing error scenarios?
ā āā Network failures ā debugging/error-testing.md, advanced/network-advanced.md
ā āā Offline (unexpected) ā debugging/error-testing.md
ā āā Offline-first/PWA ā browser-apis/service-workers.md
ā āā Error boundaries ā debugging/error-testing.md
ā āā Form validation ā testing-patterns/forms-validation.md, debugging/error-testing.md
ā
āā Refactoring existing code?
ā āā Implementing POM ā core/page-object-model.md
ā āā Improving selectors ā core/locators.md
ā āā Extracting fixtures ā core/fixtures-hooks.md
ā āā Creating data factories ā core/test-data.md
ā āā Configuration setup ā core/configuration.md
ā
āā Setting up infrastructure?
ā āā CI/CD ā infrastructure-ci-cd/ci-cd.md
ā āā GitHub Actions ā infrastructure-ci-cd/github-actions.md
ā āā GitLab CI ā infrastructure-ci-cd/gitlab.md
ā āā Other CI providers ā infrastructure-ci-cd/other-providers.md
ā āā Docker/containers ā infrastructure-ci-cd/docker.md
ā āā Sharding/parallel ā infrastructure-ci-cd/parallel-sharding.md
ā āā Reporting/artifacts ā infrastructure-ci-cd/reporting.md
ā āā Global setup/teardown ā core/global-setup.md
ā āā Project dependencies ā core/projects-dependencies.md
ā āā Test performance ā infrastructure-ci-cd/performance.md
ā āā Test coverage ā infrastructure-ci-cd/test-coverage.md
ā āā Project config ā core/configuration.md, core/projects-dependencies.md
ā
āā Organizing tests?
ā āā Skip/fixme/slow tests ā core/annotations.md
ā āā Test tags (@smoke, @fast) ā core/test-tags.md
ā āā Filtering tests (--grep) ā core/test-tags.md
ā āā Test steps ā core/annotations.md
ā āā Conditional execution ā core/annotations.md
ā
āā Running subset of tests?
āā By tag (@smoke, @critical) ā core/test-tags.md
āā Exclude slow/flaky tests ā core/test-tags.md
āā PR vs nightly tests ā core/test-tags.md, infrastructure-ci-cd/ci-cd.md
āā Project-specific filtering ā core/test-tags.md, core/configuration.md
Test Validation Loop
After writing or modifying tests:
- Run tests:
npx playwright test --reporter=list
- If tests fail:
- Review error output and trace (
npx playwright show-trace)
- Fix locators, waits, or assertions
- Re-run tests
- Only proceed when all tests pass
- Run multiple times for critical tests:
npx playwright test --repeat-each=5