playwright-best-practices

Solid

Use when writing or modifying Playwright tests (.spec.ts, .test.ts with @playwright/test imports).

Testing & QA 402 stars 39 forks Updated today

Install

View on GitHub

Quality Score: 79/100

Stars 20%
87
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
80
License 10%
0
Description 5%
100

Skill Content

# Playwright Best Practices ## CLI Context: Prevent Context Overflow When running Playwright tests from Claude Code or any CLI agent, always use minimal reporters to prevent verbose output from consuming the context window. **Use `--reporter=line` or `--reporter=dot` for CLI test runs.** Configure `playwright.config.ts` to default to minimal reporters when `CI` or `CLAUDE` env vars are set — see `playwright-patterns.md` for the config snippet. ## Locator Priority (Most to Least Resilient) Always prefer user-facing attributes: 1. `page.getByRole('button', { name: 'Submit' })` — accessibility roles 2. `page.getByLabel('Email')` — form control labels 3. `page.getByPlaceholder('Search...')` — input placeholders 4. `page.getByText('Welcome')` — visible text (non-interactive) 5. `page.getByAltText('Logo')` — image alt text 6. `page.getByTitle('Settings')` — title attributes 7. `page.getByTestId('submit-btn')` — explicit test contracts 8. CSS/XPath — last resort, avoid ## Core Rules - **Web-first assertions**: always `await expect(locator).toBeVisible()`, never `expect(await locator.isVisible()).toBe(true)` — web-first matchers auto-wait and retry - **Test isolation**: each test creates its own data; never share state between tests - **Auth state reuse**: save authenticated state via setup project + `storageState`; never log in via UI in every test - **Fixtures over beforeEach**: fixtures encapsulate setup + teardown, run on-demand, and compose ## Anti-Patterns - `page.wai...

Details

Author
aiskillstore
Repository
aiskillstore/marketplace
Created
7 months ago
Last Updated
today
Language
Python
License
None

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category