一键导入
playwright
End-to-end browser testing with Playwright. Provides guidance on writing, running, and debugging Playwright tests.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
End-to-end browser testing with Playwright. Provides guidance on writing, running, and debugging Playwright tests.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Built-in skill for asking the user questions during task execution. Use this when you need clarification, decisions, or choices from the user before proceeding.
Built-in skill for splitting tasks into sub-tasks with project matching and dependency mapping.
Built-in skill for asking the user questions during task execution. Use this when you need clarification, decisions, or choices from the user before proceeding.
Git version control best practices for AI coding agents. Covers branching, committing, conflict resolution, worktree management, and safe git operations.
Structured design methodology for AI coding agents. Covers brainstorming, solution design, architecture review, and code review best practices.
Test-Driven Development methodology for AI coding agents. Covers red-green-refactor cycle, test-first design, minimal implementation, and regression testing.
| name | playwright |
| description | End-to-end browser testing with Playwright. Provides guidance on writing, running, and debugging Playwright tests. |
You are working with Playwright for end-to-end browser testing. Follow these guidelines when writing or modifying tests.
playwright in package.json dependencies or devDependenciesplaywright.config.ts or playwright.config.js in the project rootnpm init playwright@latest or npm install -D @playwright/testnpx playwright installtests/, e2e/, or __tests__/).spec.ts or .test.ts suffiximport { test, expect } from '@playwright/test';
test.describe('Feature Name', () => {
test('should do something', async ({ page }) => {
await page.goto('/path');
await expect(page.locator('h1')).toHaveText('Expected Title');
});
});
page.getByRole() - accessibility-based, most resilientpage.getByTestId() - explicit test anchorspage.getByText() - text content matchingpage.getByLabel() - form labelspage.getByPlaceholder() - input placeholdersexpect(locator).toHaveText() for visible textexpect(locator).toBeVisible() for element presenceexpect(page).toHaveURL() for navigation checksexpect(locator).toHaveCount() for list lengthwaitFor callsawait page.click('selector') - click elementawait page.fill('selector', 'value') - fill inputawait page.selectOption('selector', 'value') - select dropdownawait page.check('selector') - check checkboxawait page.waitForSelector('selector') - wait for element# Run all tests
npx playwright test
# Run a specific test file
npx playwright test tests/example.spec.ts
# Run tests in headed mode (visible browser)
npx playwright test --headed
# Run with specific browser
npx playwright test --project=chromium
# Debug mode
npx playwright test --debug
# Generate trace for failed tests
npx playwright test --trace on-first-retry
# Show HTML report
npx playwright show-report
page.waitForTimeout(). Use waitForSelector, waitForNavigation, or auto-retrying assertions.beforeEach/afterEach for setup/teardown.data-testid attributes in components for stable test selectors.await.use: { screenshot: 'only-on-failure' } in config.use: { trace: 'on-first-retry' } for debugging.Typical playwright.config.ts:
import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
testDir: './e2e',
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: 'html',
use: {
baseURL: 'http://localhost:3000',
trace: 'on-first-retry',
screenshot: 'only-on-failure',
},
projects: [
{ name: 'chromium', use: { ...devices['Desktop Chrome'] } },
],
webServer: {
command: 'npm run dev',
url: 'http://localhost:3000',
reuseExistingServer: !process.env.CI,
},
});