SKILL.md
Playwright Test Skill
When writing end-to-end tests with Playwright:
File Location
- Place all E2E tests in the
e2edirectory. - Name files with the
.spec.tssuffix (e.g.,e2e/login.spec.ts).
Test Structure
import { test, expect } from '@playwright/test';
test.describe('Feature Name', () => {
test.beforeEach(async ({ page }) => {
// Setup (e.g., login or navigation)
});
test('should perform specific action', async ({ page }) => {
// Action
await page.goto('/some-page');
// Assertion
await expect(page.getByText('Success')).toBeVisible();
});
});
Best Practices
- Use locators that are resilient to change (e.g.,
getByRole,getByText,getByLabel). Avoid CSS selectors relying on implementation details. - Group related tests using
test.describe. - Use
await expect(...)for assertions to ensure auto-waiting. - Keep tests independent; do not rely on state from previous tests.