Two doc nits from #981 review: (1) CLAUDE.md's 'Not auto-registered' paragraph used 'integrations/<name>/src/index.ts' in one sentence and 'integrations/<name>-mcp' two sentences later — <name> meant two different things; align both to <name>-mcp. (2) skills/pw/SKILL.md 'What's Included' listed '2 MCP servers ... integrations' with no caveat, unlike README's equivalent line — add '(optional — not auto-registered)'.
4.3 KiB
Playwright Pro — Agent Context
You are working in a project with the Playwright Pro plugin installed. Follow these rules for all test-related work.
Golden Rules (Non-Negotiable)
getByRole()over CSS/XPath — resilient to markup changes, mirrors how users see the page- Never
page.waitForTimeout()— useexpect(locator).toBeVisible()orpage.waitForURL() - Web-first assertions —
expect(locator)auto-retries;expect(await locator.textContent())does not - Isolate every test — no shared state, no execution-order dependencies
baseURLin config — zero hardcoded URLs in tests- Retries:
2in CI,0locally — surface flakiness where it matters - Traces:
'on-first-retry'— rich debugging without CI slowdown - Fixtures over globals — share state via
test.extend(), not module-level variables - One behavior per test — multiple related
expect()calls are fine - Mock external services only — never mock your own app
Locator Priority
Always use the first option that works:
page.getByRole('button', { name: 'Submit' }) // 1. Role (default)
page.getByLabel('Email address') // 2. Label (form fields)
page.getByText('Welcome back') // 3. Text (non-interactive)
page.getByPlaceholder('Search...') // 4. Placeholder
page.getByAltText('Company logo') // 5. Alt text (images)
page.getByTitle('Close dialog') // 6. Title attribute
page.getByTestId('checkout-summary') // 7. Test ID (last semantic)
page.locator('.legacy-widget') // 8. CSS (last resort)
How to Use This Plugin
Generating Tests
When generating tests, always:
- Use the
Exploresubagent to scan the project structure first - Check
playwright.config.tsfortestDir,baseURL, and project settings - Load relevant templates from
templates/directory - Match the project's language (check for
tsconfig.json→ TypeScript, else JavaScript) - Place tests in the configured
testDir(default:tests/ore2e/) - Include a descriptive test name that explains the behavior being verified
Reviewing Tests
When reviewing, check against:
- All 10 golden rules above
- The anti-patterns in
skills/review/anti-patterns.md - Missing edge cases (empty state, error state, loading state)
- Proper use of fixtures for shared setup
Fixing Flaky Tests
When fixing flaky tests:
- Categorize first: timing, isolation, environment, or infrastructure
- Use
npx playwright test <file> --repeat-each=10to reproduce - Use
--trace=onfor every attempt - Apply the targeted fix from
skills/fix/flaky-taxonomy.md
Using Built-in Commands
Leverage Claude Code's built-in capabilities:
- Large migrations: Use
/batchfor parallel file-by-file conversion - Post-generation cleanup: Use
/simplifyafter generating a test suite - Debugging sessions: Use
/debugalongside/pw:fixfor trace analysis - Code review: Use
/reviewfor general code quality,/pw:pw-reviewfor Playwright-specific
Integrations
- TestRail:
TESTRAIL_URL,TESTRAIL_USER,TESTRAIL_API_KEYenv vars - BrowserStack:
BROWSERSTACK_USERNAME,BROWSERSTACK_ACCESS_KEYenv vars - Both are optional. The plugin works fully without them.
Not auto-registered (issue #978). The pw-testrail and pw-browserstack
MCP servers are no longer declared in .mcp.json. They are launched with
npx tsx integrations/<name>-mcp/src/index.ts, but the plugin ships no
node_modules and nothing installs @modelcontextprotocol/sdk, so they failed
to connect for every user (permanent red lines in claude mcp list),
regardless of whether TestRail/BrowserStack was configured. Per this repo's
"no build systems" convention we leave them out of .mcp.json rather than
vendoring node_modules. To enable one manually: cd integrations/<name>-mcp
(i.e. testrail-mcp or browserstack-mcp),
npm install, then register it in your own user/project MCP config (not the
plugin's .mcp.json) with the env vars above.
File Conventions
- Test files:
*.spec.tsor*.spec.js - Page objects:
*.page.tsin apages/directory - Fixtures:
fixtures.tsorfixtures/directory - Test data:
test-data/directory with JSON/factory files