write-playwright-test
БесплатноБез исполняемых скриптовНе проверенWrite Playwright E2E tests using fixtures and best practices. Use when creating E2E tests, writing browser automation tests, or testing user flows.
от gruckion★ 18 звёзд на GitHubОб этом скилле
Write Playwright Tests
Write end-to-end tests using Playwright fixtures, Page Object Model, and accessibility-first queries.
Core Principles
Follow Kent C. Dodds' testing philosophy:
"The more your tests resemble the way your software is used, the more confidence they can give you."
Test User Behavior, Not Implementation
- Test what users see and do
- Avoid testing internal state or methods
- Focus on outcomes, not mechanisms
Query Priority (Accessibility-First)
Use queries in this order of preference:
1. Role Queries (Best)
// Buttons, links, headings
await page.getByRole('button', { name: /submit/i })
await page.getByRole('link', { name: /home/i })
await page.getByRole('heading', { level: 1 })
// Form elements
await page.getByRole('textbox', { name: /email/i })
await page.getByRole('checkbox', { name: /remember me/i })
await page.getByRole('combobox', { name: /country/i })
// With state
await page.getByRole('checkbox', { checked: true })
await page.getByRole('tab', { selected: true })
2. Label Queries (Forms)
await page.getByLabel(/email address/i)
await page.getByLabel(/password/i)
await page.getByLabel(/phone number/i)
3. Text Queries (Content)
await page.getByText(/welcome back/i)
await page.getByText('Exact Match')
4. Placeholder Queries (Fallback)
await page.getByPlaceholder('Search...')
5. Test ID (Last Resort)
// Only when no accessible alternative exists
await page.getByTestId('complex-widget')
Fixtures
Why Use Fixtures?
- Encapsulation: Setup and teardown in one place
- Reusability: Share across all tests
- Isolation: Fresh state per test
- Auto-cleanup: Teardown runs automatically
Basic Custom Fixture
// tests/e2e/fixtures/test-fixtures.ts
import { test as base } from '@playwright/test'
type MyFixtures = {
testUser: { email: string; password: string }
}
export const test = base.extend<MyFixtures>({
testUser: async ({}, use) => {
// Setup: Create test data
const user = {
email: `test-${Date.now()}@example.com`,
password: 'TestPassword123!',
}
// Provide to test
await use(user)
// Teardown: Cleanup (runs after test)
// await deleteUser(user.email)
},
})
export { expect } from '@playwright/test'
Authentication Fixture
// tests/e2e/fixtures/auth-fixtures.ts
import { test as base, type Page } from '@playwright/test'
type AuthFixtures = {
authenticatedPage: Page
}
export const test = base.extend<AuthFixtures>({
authenticatedPage: async ({ page }, use) => {
// Login before test
await page.goto('/login')
await page.getByLabel(/email/i).fill('[email protected]')
await page.getByLabel(/password/i).fill('password123')
await page.getByRole('button', { name: /sign in/i }).click()
await page.waitForURL('/dashboard')
// Provide authenticated page
await use(page)
// Logout after test (optional)
// await page.goto('/logout')
},
})
Database Fixture with Cleanup
// tests/e2e/fixtures/db-fixtures.ts
import { test as base } from '@playwright/test'
type DbFixtures = {
insertTestData: (data: TestData) => Promise<string>
}
export const test = base.extend<DbFixtures>({
insertTestData: async ({ request }, use) => {
const createdIds: string[] = []
// Provide factory function
await use(async (data) => {
const response = await request.post('/api/test-data', { data })
const { id } = await response.json()
createdIds.push(id)
return id
})
// Cleanup all created data
for (const id of createdIds) {
await request.delete(`/api/test-data/${id}`)
}
},
})
Worker-Scoped Fixture (Shared Across Tests)
// tests/e2e/fixtures/worker-fixtures.ts
import { test as base } from '@playwright/test'
type WorkerFixtures = {
sharedAccount: { username: string; token: string }
}
export const test = base.extend<{}, WorkerFixtures>({
sharedAccount: [
async ({ browser }, use, workerInfo) => {
// Create unique account per worker
const username = `worker-${workerInfo.workerIndex}`
// Setup runs once per worker
const page = await browser.newPage()
await page.goto('/signup')
// ... create account ...
await page.close()
await use({ username, token: 'token' })
// Teardown when worker shuts down
// await deleteAccount(username)
},
{ scope: 'worker' },
],
})
Combining Multiple Fixtures
// tests/e2e/fixtures/index.ts
import { mergeTests } from '@playwright/test'
import { test as authTest } from './auth-fixtures'
import { test as dbTest } from './db-fixtures'
import { test as pageTest } from './page-fixtures'
export const test = mergeTests(authTest, dbTest, pageTest)
export { expect } from '@playwright/test'
Page Object Model
Установить write-playwright-test в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadWriteEditBashGlobGrepFAQ
Что делает скилл write-playwright-test?
Write Playwright E2E tests using fixtures and best practices. Use when creating E2E tests, writing browser automation tests, or testing user flows.
Как установить скилл write-playwright-test?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл write-playwright-test запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic