install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/pproenca/dot-skills/playwright" ~/.claude/skills/comeonoliver-skillshub-playwright-523601 && rm -rf "$T"
manifest:
skills/pproenca/dot-skills/playwright/SKILL.mdsource content
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 testarch-test-isolation
- Enable parallel test executionarch-parallel-execution
- Use Page Object Model for complex pagesarch-page-object-model
- Use fixtures for shared setuparch-fixtures
- Test against production buildsarch-test-production
- Clean up test state after each testarch-cleanup-state
2. Selectors & Locators (CRITICAL)
- Use role-based selectors over CSSloc-role-selectors
- Use data-testid for dynamic elementsloc-data-testid
- Use getByLabel for form inputsloc-label-selectors
- Use getByText for static contentloc-text-selectors
- Avoid XPath selectorsloc-avoid-xpath
- Chain locators for specificityloc-chained-locators
- Use getByPlaceholder sparinglyloc-placeholder-selector
3. Waiting & Assertions (HIGH)
- Use web-first assertionswait-web-first-assertions
- Avoid hard waitswait-avoid-hard-waits
- Use network idle for complex pageswait-network-idle
- Let actions auto-wait before interactingwait-action-retries
- Use soft assertions for non-critical checkswait-soft-assertions
- Configure timeouts appropriatelywait-custom-timeout
4. Authentication & State (HIGH)
- Reuse authentication with storage stateauth-storage-state
- Use separate storage states for different rolesauth-multiple-roles
- Handle session storage for authauth-session-storage
- Use API login for faster auth setupauth-api-login
- Use worker-scoped auth for parallel testsauth-parallel-workers
5. Mocking & Network (MEDIUM-HIGH)
- Mock API responses for deterministic testsmock-api-responses
- Intercept and modify real responsesmock-intercept-modify
- Use HAR files for complex mock scenariosmock-har-files
- Abort unnecessary requestsmock-abort-requests
- Simulate network conditionsmock-network-conditions
6. Next.js Integration (MEDIUM)
- Wait for hydration before interactingnext-wait-hydration
- Test server components correctlynext-server-components
- Test App Router navigation patternsnext-app-router-navigation
- Test server actions end-to-endnext-server-actions
- Configure baseURL for clean navigationnext-baseurl-config
7. Performance & Speed (MEDIUM)
- Use sharding for large test suitesperf-sharding
- Use headless mode in CIperf-headless-ci
- Select browsers strategicallyperf-browser-selection
- Reuse development server when possibleperf-reuse-server
- Configure retries for flaky test recoveryperf-retries
8. Debugging & CI (LOW-MEDIUM)
- Use trace viewer for failed testsdebug-trace-viewer
- Capture screenshots and videos on failuredebug-screenshots-videos
- Use Playwright Inspector for interactive debuggingdebug-inspector
- Configure reporters for CI integrationdebug-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 |