Playwright Pro
Production-grade Playwright testing. These golden rules and locator priorities govern all Playwright work (generation, review, fixing, migration).
Golden rules (non-negotiable)
getByRole() over CSS/XPath — resilient to markup changes.
- Never
page.waitForTimeout() — use web-first assertions (expect(locator).toBeVisible(), page.waitForURL()).
expect(locator) auto-retries; expect(await locator.textContent()) does not.
- Isolate every test — no shared state, no execution-order dependencies.
baseURL in config — zero hardcoded URLs.
- Retries:
2 in CI, 0 locally.
- Traces:
'on-first-retry' — rich debugging without CI slowdown.
- Fixtures over globals —
test.extend() for shared state.
- One behavior per test — multiple related assertions are fine.
- Mock external services only — never mock your own app.
Locator priority (use the first that works)
1. getByRole() — buttons, links, headings, form elements
2. getByLabel() — form fields with labels
3. getByText() — non-interactive text
4. getByPlaceholder() — inputs with placeholder
5. getByAltText() — images
6. getByTitle() — title attribute
7. getByTestId() — when no semantic option exists
8. page.locator() — CSS/XPath as last resort
Recommended sequence
- Init — scaffold config, CI pipeline, first smoke test.
- Generate — tests from a spec or URL.
- Review — validate quality, flag anti-patterns. Always after generate, before commit.
- Fix — diagnose and repair failing/flaky tests when CI turns red.
Validation checkpoints: run review after generate (catches locator anti-patterns + missing assertions); re-run full suite locally after a fix; run coverage after a migration to confirm parity before decommissioning the old suite.
Flaky-test categories (see the fix method for full taxonomy)
Timing/Async (fails intermittently everywhere) · Test Isolation (fails in suite, passes alone) · Environment (fails in CI, passes locally) · Infrastructure (random, references browser internals).
File conventions
Tests *.spec.ts/.js · page objects *.page.ts in pages/ · fixtures fixtures.ts or fixtures/ · test data in test-data/.
Optional integrations (env vars)
TestRail: TESTRAIL_URL, TESTRAIL_USER, TESTRAIL_API_KEY. BrowserStack: BROWSERSTACK_USERNAME, BROWSERSTACK_ACCESS_KEY. Both optional — the toolkit works fully without them.
1---2name: playwright-pro3description: Use when working with Playwright tests, end-to-end testing, browser automation, flaky tests, test migration, or CI test suites — the golden rules and locator priority that govern all Playwright work.4tags: [playwright, e2e, browser-automation, testing, flaky-tests, locators, web-first-assertions, ci, getbyrole, fixtures]5source: alirezarezvani/claude-skills6derived_from: engineering-team/playwright-pro/skills/pw7metadata:8 source: https://skillmd.com/skills/aashutosh396/playwright-pro9---1011# Playwright Pro1213Production-grade Playwright testing. These golden rules and locator priorities govern all Playwright work (generation, review, fixing, migration).1415## Golden rules (non-negotiable)161. `getByRole()` over CSS/XPath — resilient to markup changes.172. Never `page.waitForTimeout()` — use web-first assertions (`expect(locator).toBeVisible()`, `page.waitForURL()`).183. `expect(locator)` auto-retries; `expect(await locator.textContent())` does not.194. Isolate every test — no shared state, no execution-order dependencies.205. `baseURL` in config — zero hardcoded URLs.216. Retries: `2` in CI, `0` locally.227. Traces: `'on-first-retry'` — rich debugging without CI slowdown.238. Fixtures over globals — `test.extend()` for shared state.249. One behavior per test — multiple related assertions are fine.2510. Mock external services only — never mock your own app.2627## Locator priority (use the first that works)28```291. getByRole() — buttons, links, headings, form elements302. getByLabel() — form fields with labels313. getByText() — non-interactive text324. getByPlaceholder() — inputs with placeholder335. getByAltText() — images346. getByTitle() — title attribute357. getByTestId() — when no semantic option exists368. page.locator() — CSS/XPath as last resort37```3839## Recommended sequence401. Init — scaffold config, CI pipeline, first smoke test.412. Generate — tests from a spec or URL.423. Review — validate quality, flag anti-patterns. Always after generate, before commit.434. Fix — diagnose and repair failing/flaky tests when CI turns red.4445Validation checkpoints: run review after generate (catches locator anti-patterns + missing assertions); re-run full suite locally after a fix; run coverage after a migration to confirm parity before decommissioning the old suite.4647## Flaky-test categories (see the fix method for full taxonomy)48Timing/Async (fails intermittently everywhere) · Test Isolation (fails in suite, passes alone) · Environment (fails in CI, passes locally) · Infrastructure (random, references browser internals).4950## File conventions51Tests `*.spec.ts`/`.js` · page objects `*.page.ts` in `pages/` · fixtures `fixtures.ts` or `fixtures/` · test data in `test-data/`.5253## Optional integrations (env vars)54TestRail: `TESTRAIL_URL`, `TESTRAIL_USER`, `TESTRAIL_API_KEY`. BrowserStack: `BROWSERSTACK_USERNAME`, `BROWSERSTACK_ACCESS_KEY`. Both optional — the toolkit works fully without them.