playwright-best-practices

0xbigboss/claude-code · updated Apr 8, 2026

$npx skills add https://github.com/0xbigboss/claude-code --skill playwright-best-practices
0 commentsdiscussion
summary

When running Playwright tests from Claude Code or any CLI agent, always use minimal reporters to prevent verbose output from consuming the context window.

skill.md

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.waitForTimeout(ms) — use auto-waiting locators instead
  • page.locator('.class') — use role/label/testid
  • XPath selectors — fragile, use user-facing attributes
  • Shared state between tests — each test creates own data
  • UI login in every test — use setup project + storageState
  • Manual assertions without await — use web-first assertions
  • Hardcoded waits — rely on Playwright's auto-waiting
  • Default reporter in CI/agent — use --reporter=line or --reporter=dot

Checklist

  • Locators use role/label/testid, not CSS classes or XPath
  • All assertions use await expect() web-first matchers
  • Page objects define locators in constructor
  • No page.waitForTimeout() — use auto-waiting
  • Tests isolated — no shared state
  • Auth state reused via setup project
  • Network mocks set up before navigation
  • Test data created per-test or via fixtures
  • Debug logging added for complex flows
  • Minimal reporter (line/dot) used in CI/agent contexts

See playwright-patterns.md for Page Object Model, fixtures, network mocking, and configuration examples.

Discussion

Product Hunt–style comments (not star reviews)
  • No comments yet — start the thread.
general reviews

Ratings

4.531 reviews
  • Ganesh Mohane· Dec 20, 2024

    playwright-best-practices has been reliable in day-to-day use. Documentation quality is above average for community skills.

  • Aisha Kapoor· Dec 16, 2024

    Keeps context tight: playwright-best-practices is the kind of skill you can hand to a new teammate without a long onboarding doc.

  • Rahul Santra· Nov 11, 2024

    Keeps context tight: playwright-best-practices is the kind of skill you can hand to a new teammate without a long onboarding doc.

  • Kofi Okafor· Nov 7, 2024

    playwright-best-practices has been reliable in day-to-day use. Documentation quality is above average for community skills.

  • Daniel Haddad· Oct 26, 2024

    playwright-best-practices fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.

  • Pratham Ware· Oct 2, 2024

    We added playwright-best-practices from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.

  • Piyush G· Sep 9, 2024

    Useful defaults in playwright-best-practices — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.

  • Luis Malhotra· Sep 9, 2024

    Keeps context tight: playwright-best-practices is the kind of skill you can hand to a new teammate without a long onboarding doc.

  • Kofi Park· Sep 5, 2024

    I recommend playwright-best-practices for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.

  • Shikha Mishra· Aug 28, 2024

    Registry listing for playwright-best-practices matched our evaluation — installs cleanly and behaves as described in the markdown.

showing 1-10 of 31

1 / 4