playwright-testing
Skill1 starsChanged 9 months agoApache-2.0View on GitHub
End-to-end testing with Playwright using role-based locators, auto-waiting, network mocking, visual regression, fixtures for test isolation, parallel execution, CI integration, authentication state reuse, and trace viewer debugging. Use when building reliable browser automation tests that catch regressions before production.
- Reads credentials
8 other projects use a version of this.
Adopted by
Most recently taken up by
- ZeroTokenClaw/agents-skillstheir own version, first seen Sep 21, 2026
- navikt/copilottheir own version, first seen Sep 14, 2026
- n-n-code/n-n-code-skillstheir own version, first seen Sep 5, 2026
- alinaqi/maggytheir own version, first seen Jun 12, 2026
- jorgeasaurus/agent-skillstheir own version, first seen May 11, 2026
- chongdashu/vibejam-starter-packtheir own version, first seen Apr 15, 2026
Other versions8 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 8
- alinaqi/maggy★ 707same name
- chongdashu/vibejam-starter-pack★ 149same name
- navikt/copilot★ 54same name
- chongdashu/threejs-tactics-game★ 32same name
- jorgeasaurus/agent-skills★ 13same name
- n-n-code/n-n-code-skills★ 4same name
- dtinth/agent-skills★ 2same name
- ZeroTokenClaw/agents-skills★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository73 other files it gives its agents.
- accessibility-wcagSkill
- api-designSkill
- api-testingSkill
- asset-optimizationSkill
- audio-systemsSkill
- aws-essentialsSkill
- ci-cd-pipelinesSkill
- codebase-analysisSkill
- code-reviewerSkill
- container-securitySkill
- cost-optimizationSkill
- database-designSkill
- data-visualizationSkill
- doc-generationSkill
- docker-kubernetesSkill
- docxSkill
- email-notificationsSkill
- env-configSkill
- flutter-mobileSkill
- framer-motionSkill
- frontend-code-reviewSkill
- frontend-designSkill
- fullstack-developerSkill
- game-enginesSkill
- gameplay-designSkill
- game-programming-languagesSkill
- game-serversSkill
- git-workflowSkill
- godot-4Skill
- golang-proSkill
- go-linter-configurationSkill
- graphics-renderingSkill
- i18n-localizationSkill
- incident-responseSkill
- level-designSkill
- llm-integrationSkill
- local-securitySkill
- memory-managementSkill
- monetization-systemsSkill
- monitoring-observabilitySkill
- multiplayer-netcodeSkill
- nextjs-16Skill
- notebooklm-researchSkill
- npm-packageSkill
- oauth-authSkill
- particle-systemsSkill
- performance-optimizationSkill
- postgres-advancedSkill
- programming-architectureSkill
- project-migrationSkill
- publishing-platformsSkill
- python-best-practicesSkill
- react-nativeSkill
- redis-patternsSkill
- refactoring-patternsSkill
- remotion-best-practicesSkill
- rust-best-practicesSkill
- scraping-automationSkill
- security-reviewSkill
- seo-metaSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
5 rules. 0 are common, 2 are distinctive, and 3 are very specific to this project.
0
Common
Most of the 8 edited versions we read keep these.
2
Distinctive
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 50
GOOD: Use auto-waiting assertions.
- Distinctive: line 147
Avoid logging in for every test.
- Very specific: line 306
Selector not found: Use npx playwright codegen to validate locators.
- Very specific: line 310
Network mocking not working: Ensure page.route() is called before navigation.
- Very specific: line 312
Parallel tests interfering: Use test.describe.serial() or unique test data per worker.
“Common” is measured: kept by at least 6 in 10 of the 8 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Locator Strategies
BAD: CSS selectors couple tests to implementation. Breaks on refactors.
await page.locator('.btn-primary.submit-form').click();
await page.locator('#username-input').fill('alice');GOOD: Semantic locators match user perception. Resilient to markup changes.
await page.getByRole('button', { name: 'Submit' }).click();
await page.getByLabel('Username').fill('alice');
await page.getByText('Welcome back').waitFor();
await page.getByPlaceholder('Search...').fill('query');
await page.getByTestId('checkout-total').textContent(); // Only when no semantic optionBAD: Fragile global selectors. Breaks with duplicate elements.
await page.getByRole('button', { name: 'Delete' }).click(); // Which delete button?GOOD: Chain locators to scope within a parent container.
const row = page.getByRole('row', { name: 'Alice' });
await row.getByRole('button', { name: 'Delete' }).click();
await page.getByRole('listitem').filter({ hasText: 'Active' }).first().click();Auto-Waiting and Assertions
BAD: Hardcoded delays cause flakiness and slow tests.
await page.waitForTimeout(2000);
await page.locator('.spinner').waitFor({ state: 'hidden' });
await page.locator('button').click();GOOD: Use auto-waiting assertions. Retry until condition is met.
await expect(page.getByRole('button', { name: 'Submit' })).toBeVisible();
await expect(page.getByText('Loading...')).not.toBeVisible();
await expect(page.getByLabel('Email')).toHaveValue('alice@example.com');
await expect(page.getByRole('checkbox', { name: 'Terms' })).toBeChecked();
await expect(page.getByText('Report')).toBeVisible({ timeout: 30000 }); // Custom timeoutNetwork Mocking
BAD: Hitting real APIs in tests. Flaky, slow, pollutes production data.
await page.goto('/users');GOOD: Mock API responses with route.fulfill(). Fast, deterministic.
await page.route('**/api/users', async (route) => {
await route.fulfill({
status: 200,
body: JSON.stringify([{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }]),
});
});
await page.goto('/users');
await expect(page.getByText('Alice')).toBeVisible();
// Conditional mocking
await page.route('**/api/**', async (route) => {
route.request().url().includes('/logout') ? route.fulfill({ status: 200 }) : route.continue();
});
// Speed up tests by blocking resources
await page.route('**/*.{png,jpg,jpeg,webp}', (route) => route.abort());Visual Regression Testing
await expect(page).toHaveScreenshot('homepage.png');
await expect(page.getByRole('banner')).toHaveScreenshot('header.png'); // Component-level
await expect(page).toHaveScreenshot({ mask: [page.getByText(/Last updated:.*/)] }); // Mask dynamicUpdate baselines: npx playwright test --update-snapshots
Fixtures and Test Isolation
BAD: Shared state leaks between tests. Failure in test 1 breaks test 2.
let page;
test.beforeAll(async ({ browser }) => { page = await browser.newPage(); });
test('test 1', async () => { await page.fill('input', 'admin'); });
test('test 2', async () => { /* Still has 'admin' from test 1 */ });GOOD: Isolated context per test. No side effects.
test('login as admin', async ({ page }) => {
await page.goto('/login');
await page.getByLabel('Username').fill('admin');
await page.getByRole('button', { name: 'Login' }).click();
await expect(page.getByText('Welcome, admin')).toBeVisible();
});GOOD: Custom fixtures for reusable setup.
import { test as base } from '@playwright/test';
type Fixtures = { authenticatedPage: Page };
export const test = base.extend<Fixtures>({
authenticatedPage: async ({ page }, use) => {
await page.goto('/login');
await page.getByLabel('Email').fill('admin@example.com');
await page.getByLabel('Password').fill('admin123');
await page.getByRole('button', { name: 'Login' }).click();
await expect(page.getByText('Dashboard')).toBeVisible();
await use(page);
},
});
test('view admin dashboard', async ({ authenticatedPage }) => {
await authenticatedPage.goto('/admin');
await expect(authenticatedPage.getByRole('heading', { name: 'Admin Panel' })).toBeVisible();
});Authentication State Reuse
Avoid logging in for every test. Save auth state once, reuse across tests.
// auth.setup.ts
import { test as setup } from '@playwright/test';
setup('authenticate', async ({ page }) => {
await page.goto('/login');
await page.getByLabel('Email').fill('admin@example.com');
await page.getByLabel('Password').fill('admin123');
await page.getByRole('button', { name: 'Login' }).click();
await page.waitForURL('/dashboard');
await page.context().storageState({ path: 'auth.json' });
});
// test.spec.ts
test.use({ storageState: 'auth.json' });
test('access protected page', async ({ page }) => {
await page.goto('/admin');
await expect(page.getByRole('heading', { name: 'Admin Panel' })).toBeVisible();
});Configure in playwright.config.ts:
export default defineConfig({
projects: [
{ name: 'setup', testMatch: /.*\.setup\.ts/ },
{ name: 'chromium', use: { storageState: 'auth.json' }, dependencies: ['setup'] },
],
});Parallel Execution
export default defineConfig({
workers: process.env.CI ? 2 : 4,
fullyParallel: true,
});
// Disable for tests that share global state
test.describe.serial('checkout flow', () => {
test('add item to cart', async ({ page }) => { /* ... */ });
test('proceed to checkout', async ({ page }) => { /* ... */ });
});
// Use unique data per worker to avoid collisions
test('create user', async ({ page }) => {
const workerId = test.info().parallelIndex;
const email = `user${workerId}@example.com`;
await page.getByLabel('Email').fill(email);
});CI Integration
name: Playwright Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: npm ci
- run: npx playwright install --with-deps
- run: npx playwright test
- uses: actions/upload-artifact@v4
if: failure()
with:
name: playwright-report
path: playwright-report/
# Shard tests for faster CI
strategy:
matrix:
shardIndex: [1, 2, 3, 4]
shardTotal: [4]
steps:
- run: npx playwright test --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}Debugging
npx playwright test --trace on # Record trace, view with show-report
npx playwright test --headed --slowmo=1000 # Watch tests in real-time
npx playwright test --debug # Step through with inspector
npx playwright codegen http://localhost:3000 # Generate selectorsCapture traces on failure:
export default defineConfig({
use: { trace: 'on-first-retry' },
retries: process.env.CI ? 2 : 0,
});Set breakpoints with page.pause():
test('debug login', async ({ page }) => {
await page.goto('/login');
await page.pause(); // Playwright Inspector opens
await page.getByLabel('Email').fill('admin@example.com');
});Capture console and network logs:
page.on('console', (msg) => msg.type() === 'error' && console.log('Error:', msg.text()));
page.on('request', (req) => console.log('Request:', req.url()));Page Object Model
BAD: Duplicating selectors and workflows across tests.
test('user can login', async ({ page }) => {
await page.goto('/login');
await page.getByLabel('Email').fill('user@example.com');
await page.getByRole('button', { name: 'Login' }).click();
});GOOD: Centralize page logic. Tests express intent, not mechanics.
class LoginPage {
constructor(private page: Page) {}
async goto() { await this.page.goto('/login'); }
async login(email: string, password: string) {
await this.page.getByLabel('Email').fill(email);
await this.page.getByLabel('Password').fill(password);
await this.page.getByRole('button', { name: 'Login' }).click();
}
async expectWelcome() {
await expect(this.page.getByText('Welcome')).toBeVisible();
}
}
test('user can login', async ({ page }) => {
const loginPage = new LoginPage(page);
await loginPage.goto();
await loginPage.login('user@example.com', 'pass123');
await loginPage.expectWelcome();
});Troubleshooting
Flaky tests: Enable retries and traces. Use auto-waiting assertions instead of hardcoded delays.
Selector not found: Use npx playwright codegen to validate locators. Prefer semantic locators over CSS.
Timeouts: Increase timeout for slow operations: await expect(page.getByText('Data')).toBeVisible({ timeout: 30000 });
Network mocking not working: Ensure page.route() is called before navigation. Routes apply to requests made after registration.
Parallel tests interfering: Use test.describe.serial() or unique test data per worker.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

