playwright
Original:🇺🇸 English
Translated
Playwright testing best practices for Next.js applications (formerly test-playwright). This skill should be used when writing, reviewing, or debugging E2E tests with Playwright. Triggers on tasks involving test selectors, flaky tests, authentication state, API mocking, hydration testing, parallel execution, CI configuration, or debugging test failures.
41installs
Sourcepproenca/dot-skills
Added on
NPX Install
npx skill4agent add pproenca/dot-skills playwrightTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Playwright + Next.js Testing Best Practices
Comprehensive testing optimization guide for Playwright with Next.js applications. Contains 43 rules across 8 categories, prioritized by impact to guide reliable, fast, and maintainable E2E tests.
When to Apply
Reference these guidelines when:
- Writing new Playwright tests for Next.js apps
- Debugging flaky or failing tests
- Optimizing test execution speed
- Setting up authentication state reuse
- Configuring CI/CD pipelines for testing
- Testing Server Components and App Router features
- Reviewing test code for reliability issues
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Test Architecture | CRITICAL | |
| 2 | Selectors & Locators | CRITICAL | |
| 3 | Waiting & Assertions | HIGH | |
| 4 | Authentication & State | HIGH | |
| 5 | Mocking & Network | MEDIUM-HIGH | |
| 6 | Next.js Integration | MEDIUM | |
| 7 | Performance & Speed | MEDIUM | |
| 8 | Debugging & CI | LOW-MEDIUM | |
Quick Reference
1. Test Architecture (CRITICAL)
- - Use fresh browser context for each test
arch-test-isolation - - Enable parallel test execution
arch-parallel-execution - - Use Page Object Model for complex pages
arch-page-object-model - - Use fixtures for shared setup
arch-fixtures - - Test against production builds
arch-test-production - - Clean up test state after each test
arch-cleanup-state
2. Selectors & Locators (CRITICAL)
- - Use role-based selectors over CSS
loc-role-selectors - - Use data-testid for dynamic elements
loc-data-testid - - Use getByLabel for form inputs
loc-label-selectors - - Use getByText for static content
loc-text-selectors - - Avoid XPath selectors
loc-avoid-xpath - - Chain locators for specificity
loc-chained-locators - - Use getByPlaceholder sparingly
loc-placeholder-selector
3. Waiting & Assertions (HIGH)
- - Use web-first assertions
wait-web-first-assertions - - Avoid hard waits
wait-avoid-hard-waits - - Use network idle for complex pages
wait-network-idle - - Let actions auto-wait before interacting
wait-action-retries - - Use soft assertions for non-critical checks
wait-soft-assertions - - Configure timeouts appropriately
wait-custom-timeout
4. Authentication & State (HIGH)
- - Reuse authentication with storage state
auth-storage-state - - Use separate storage states for different roles
auth-multiple-roles - - Handle session storage for auth
auth-session-storage - - Use API login for faster auth setup
auth-api-login - - Use worker-scoped auth for parallel tests
auth-parallel-workers
5. Mocking & Network (MEDIUM-HIGH)
- - Mock API responses for deterministic tests
mock-api-responses - - Intercept and modify real responses
mock-intercept-modify - - Use HAR files for complex mock scenarios
mock-har-files - - Abort unnecessary requests
mock-abort-requests - - Simulate network conditions
mock-network-conditions
6. Next.js Integration (MEDIUM)
- - Wait for hydration before interacting
next-wait-hydration - - Test server components correctly
next-server-components - - Test App Router navigation patterns
next-app-router-navigation - - Test server actions end-to-end
next-server-actions - - Configure baseURL for clean navigation
next-baseurl-config
7. Performance & Speed (MEDIUM)
- - Use sharding for large test suites
perf-sharding - - Use headless mode in CI
perf-headless-ci - - Select browsers strategically
perf-browser-selection - - Reuse development server when possible
perf-reuse-server - - Configure retries for flaky test recovery
perf-retries
8. Debugging & CI (LOW-MEDIUM)
- - Use trace viewer for failed tests
debug-trace-viewer - - Capture screenshots and videos on failure
debug-screenshots-videos - - Use Playwright Inspector for interactive debugging
debug-inspector - - Configure reporters for CI integration
debug-ci-reporters
How to Use
Read individual reference files for detailed explanations and code examples:
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
Reference Files
| File | Description |
|---|---|
| AGENTS.md | Complete compiled guide with all rules |
| references/_sections.md | Category definitions and ordering |
| assets/templates/_template.md | Template for new rules |
| metadata.json | Version and reference information |