borghei/Claude-Skills / engineering/playwright-pro
playwright-pro
VerifiedEnd-to-end testing with Playwright: test generation, page objects, locator strategy, flaky- test diagnosis, visual regression, and CI integration. Use when writing E2E tests, fixing flaky tests, or migrating from Cypress/Selenium.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 10.6 KB |
| assets/flawed_tests/profile.spec.ts | script | 468 B |
| assets/reports/run1.json | config | 1.2 KB |
| assets/reports/run2.json | config | 1.3 KB |
| assets/reports/run3.json | config | 1.4 KB |
| assets/sample_flows.json | config | 800 B |
| assets/sample_login.html | other | 489 B |
| assets/tests/login.spec.ts | script | 906 B |
| references/core-rules-and-patterns.md | markdown | 7.2 KB |
| references/diagnosis-migration-and-ci.md | markdown | 8.7 KB |
| references/playwright-patterns.md | markdown | 4.5 KB |
| scripts/coverage_mapper.py | script | 11.0 KB |
| scripts/flaky_detector.py | script | 10.6 KB |
| scripts/page_object_generator.pyexecutable | script | 14.8 KB |
| scripts/test_analyzer.pyexecutable | script | 12.3 KB |
| scripts/test_generator.py | script | 11.1 KB |
| scripts/test_report_parser.pyexecutable | script | 14.8 KB |
| skills/browserstack.md | markdown | 2.4 KB |
| skills/coverage.md | markdown | 1.9 KB |
| skills/fix.md | markdown | 2.6 KB |
| skills/generate.md | markdown | 2.4 KB |
| skills/init.md | markdown | 2.1 KB |
| skills/migrate.md | markdown | 2.5 KB |
| skills/report.md | markdown | 2.0 KB |
| skills/review.md | markdown | 2.2 KB |
| skills/testrail.md | markdown | 2.5 KB |
references/playwright-patterns.md
View on GitHub# Playwright Patterns Reference
## Locator Strategy Decision Tree
```
Need to find an element?
├── Does it have a semantic role? (button, link, heading, textbox)
│ └── YES → getByRole('role', { name: 'visible text' })
├── Is it a labeled form field?
│ └── YES → getByLabel('Label text')
├── Does it have visible text content?
│ └── YES → getByText('Text content')
├── Does it have a placeholder?
│ └── YES → getByPlaceholder('Placeholder text')
├── Does it have a data-testid?
│ └── YES → getByTestId('test-id')
└── Last resort
└── page.locator('css-selector')
```
## Assertion Patterns
### Web-First (Auto-Retrying) Assertions
These assertions automatically retry until the condition is met or the timeout expires:
```typescript
await expect(locator).toBeVisible();
await expect(locator).toBeHidden();
await expect(locator).toBeEnabled();
await expect(locator).toBeDisabled();
await expect(locator).toHaveText('exact text');
await expect(locator).toContainText('partial text');
await expect(locator).toHaveValue('input value');
await expect(locator).toHaveAttribute('name', 'value');
await expect(locator).toHaveCount(5);
await expect(locator).toHaveClass(/active/);
await expect(page).toHaveURL(/\/dashboard/);
await expect(page).toHaveTitle('Page Title');
```
### Non-Retrying (Avoid in Tests)
These evaluate once and do NOT retry:
```typescript
// BAD: Does not auto-retry
expect(await locator.textContent()).toBe('text');
expect(await locator.isVisible()).toBe(true);
expect(await page.title()).toBe('Title');
```
## Fixture Patterns
### Custom Test Fixture
```typescript
import { test as base, expect } from '@playwright/test';
import { LoginPage } from '../pages/login.page';
type Fixtures = {
loginPage: LoginPage;
authenticatedPage: Page;
};
export const test = base.extend<Fixtures>({
loginPage: async ({ page }, use) => {
const loginPage = new LoginPage(page);
await loginPage.goto();
await use(loginPage);
},
authenticatedPage: async ({ browser }, use) => {
const context = await browser.newContext({
storageState: 'playwright/.auth/user.json',
});
const page = await context.newPage();
await use(page);
await context.close();
},
});
```
### Worker-Scoped Fixture (Shared Across Tests)
```typescript
export const test = base.extend<{}, { dbConnection: Connection }>({
dbConnection: [async ({}, use) => {
const conn = await createConnection();
await use(conn);
await conn.close();
}, { scope: 'worker' }],
});
```
## Network Mocking Patterns
### Mock API Response
```typescript
await page.route('/api/users', async (route) => {
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify([{ id: 1, name: 'Test User' }]),
});
});
```
### Intercept and Modify Response
```typescript
await page.route('/api/config', async (route) => {
const response = await route.fetch();
const json = await response.json();
json.featureFlag = true;
await route.fulfill({ response, body: JSON.stringify(json) });
});
```
### Wait for API Call
```typescript
const responsePromise = page.waitForResponse('/api/submit');
await page.getByRole('button', { name: 'Submit' }).click();
const response = await responsePromise;
expect(response.status()).toBe(200);
```
## Anti-Pattern Quick Reference
| Anti-Pattern | Fix |
|-------------|-----|
| `page.waitForTimeout(N)` | `await expect(locator).toBeVisible()` |
| `expect(await el.textContent())` | `await expect(el).toHaveText()` |
| `page.locator('.class-name')` | `page.getByRole('button', { name: '...' })` |
| `{ force: true }` | Fix underlying visibility issue |
| Global `let page` variable | Use Playwright fixtures |
| `page.goto('http://localhost:3000/path')` | `page.goto('/path')` with baseURL |
| `for` loop running test N times | Use `test.describe.configure({ retries: N })` |
| Shared mutable state between tests | `test.beforeEach` setup or fixtures |
## CI Configuration Patterns
### Sharding (Split Tests Across Workers)
```yaml
strategy:
matrix:
shard: [1/4, 2/4, 3/4, 4/4]
steps:
- run: npx playwright test --shard=${{ matrix.shard }}
```
### Merge Shard Reports
```bash
npx playwright merge-reports --reporter html ./all-blob-reports
```
### Conditional Browser Installation
```bash
# Install only what you need
npx playwright install --with-deps chromium # CI: fast
npx playwright install --with-deps # Full: all browsers
```
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |