playwright

A set of rules for Playwright, a tool that tests websites by acting like a user in a browser. It covers end-to-end tests, page objects, test fixtures, selectors, and assertions.

In plain words
What is it for?
Use it when creating or maintaining Playwright tests for pages and user journeys such as authentication, navigation, or checkout.
Why use it?
It provides consistent ways to write reliable browser tests and avoid fragile element lookups, fixed delays, and tests that depend on one another.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/nedcodes-ok/cursor-doctor/playwright
Clone the repo
git clone --depth 1 https://github.com/nedcodes-ok/cursor-doctor
Per session 643 This file is loaded in full into every session.
When invoked 643 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00643 $0.00643
Opus 5 $0.00321 $0.00321
Sonnet 5 $0.00129 $0.00129
Haiku 4.5 $0.00064 $0.00064

Measured yesterday against content hash fda83a373eec, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

playwright scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

pro-kit/templates/tools/playwright.mdc · 57 lines

How it starts

The opening of the file, as written. The whole thing — 57 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Playwright Cursor Rules

You are an expert in Playwright end-to-end testing. Follow these rules:

Test Structure

  • One test file per feature or page: tests/auth.spec.ts, tests/checkout.spec.ts
  • Use test.describe() to group related tests
  • Test names should describe user behavior: test('user can add item to cart and checkout')
  • Keep tests independent — no test should depend on another test's state
  • Use test.beforeEach for common setup (login, navigation)

Selectors

  • Use getByRole() as the primary selector: page.getByRole('button', { name: 'Submit' })
  • Use getByText(), getByLabel(), getByPlaceholder() for user-visible elements
  • Use getByTestId() only when no accessible selector exists — add data-testid as last resort
  • Never use CSS selectors or XPath for elements users interact with
  • Chain locators: page.getByRole('listitem').filter({ hasText: 'Product A' })

Assertions

  • Use web-first assertions: await expect(page.getByText('Success')).toBeVisible()
  • Never use page.waitForTimeout() — use expect with auto-waiting or waitForSelector
  • Assert on visible state, not DOM existence: toBeVisible() over toBeAttached()
  • Use toHaveURL(), toHaveTitle() for navigation assertions
  • Use soft assertions (expect.soft) for non-critical checks within a test

Page Object Model

  • Create page objects for reusable interactions: class LoginPage { constructor(private page: Page) {} }
  • Page objects expose actions (login, fillForm) not raw locators
  • Return new page objects from navigation actions: async goToSettings() { return new SettingsPage(this.page) }
  • Keep assertions in tests, not in page objects

Fixtures

  • Extend the base test with custom fixtures: test.extend<{ adminPage: AdminPage }>()
  • Use fixtures for authenticated state, seeded data, and test accounts
  • Store auth state with storageState for reuse across tests
  • Use worker-scoped fixtures for expensive setup (database seeding)

Anti-Patterns — Do NOT

  • ❌ Using page.waitForTimeout(2000) — always wait for a specific condition
  • ❌ Using page.$() or page.$$() — use locator API
  • ❌ Testing implementation details (CSS classes, internal state)
  • ❌ Sharing state between test files via global variables
  • ❌ Hard-coding URLs — use baseURL in playwright.config.ts
  • ❌ Ignoring flaky tests — fix the root cause or add proper waiting

Read the full file on GitHub · 57 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 57 lines · 643 tokens per session scan A fda83a373eec

Subscribe to this mod's changes

playwright is a cursor rule published in the GitHub repository nedcodes-ok/cursor-doctor (9 stars, last pushed 5mo ago), licensed MIT. It adds 643 tokens to every session, about $0.0032 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.