AGENTS.md — Playwright
Official Playwright e2e best practices (https://playwright.dev/docs/best-practices). Use @playwright/test.
- Test user-visible behaviour, not implementation details (function names, CSS classes, DOM structure).
- Prefer user-facing locators:
getByRole,getByText,getByLabel,getByPlaceholder,getByAltText,getByTitle. UsegetByTestIdonly when none fit. - Don't use CSS or XPath selectors — they break when the DOM changes.
- Narrow with chaining +
filter({ hasText })/filter({ has })instead of.first()/.nth(). - Use web-first auto-retrying assertions:
await expect(locator).toBeVisible()— neverexpect(await locator.isVisible()).toBe(true). - Put
awaitbeforeexpect, not inside it. - Use
expect.soft()to collect multiple failures in one run. - Don't use manual waits (
waitForTimeout); let locators and assertions auto-wait. - Keep tests isolated: own storage/cookies/data per test; share setup via
beforeEach/afterEach. - Reuse auth via a setup project +
storageState, not per-test login. - Mock third-party responses with
page.route(); don't test sites you don't own. - Run across Chromium, Firefox, WebKit via
projectsinplaywright.config.ts. - On CI install only needed browsers:
npx playwright install chromium --with-deps; capture traceson-first-retry. - Lint with TS + ESLint
@typescript-eslint/no-floating-promises; runtsc --noEmit. - Generate locators with
npx playwright codegen <url>; keep Playwright updated with@playwright/test@latest.