← スキル一覧に戻る

playwright
by Raphael67
My dotfiles
⭐ 0🍴 0📅 2026年1月18日
SKILL.md
name: playwright description: Write Playwright tests, migrate from Cypress, and answer Playwright questions. Use when working with e2e tests, browser automation, Playwright, or migrating from Cypress. user-invocable: false
Playwright Testing Skill
Quick Start
import { test, expect } from '@playwright/test';
test('example test', async ({ page }) => {
await page.goto('https://example.com');
await expect(page).toHaveTitle(/Example/);
await page.getByRole('button', { name: 'Submit' }).click();
await expect(page.getByText('Success')).toBeVisible();
});
Project Setup
# Initialize new project
npm init playwright@latest
# Install in existing project
npm install -D @playwright/test
npx playwright install
Core Concepts
Locators (Prefer User-Facing)
page.getByRole('button', { name: 'Submit' }) // Best: accessibility
page.getByText('Welcome') // By visible text
page.getByLabel('Email') // Form fields
page.getByTestId('submit-btn') // data-testid fallback
page.locator('css-selector') // Last resort
Assertions (Auto-Retry)
await expect(locator).toBeVisible();
await expect(locator).toHaveText('Hello');
await expect(page).toHaveURL(/dashboard/);
Test Structure
test.describe('Feature', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/');
});
test('scenario', async ({ page }) => {
// test code
});
});
Reference Files
| File | Use When |
|---|---|
| REFERENCE.md | Need API details for locators, assertions, config |
| CYPRESS-MIGRATION.md | Converting Cypress tests to Playwright |
| PATTERNS.md | Implementing POM, auth, mocking, visual tests |
Common Commands
npx playwright test # Run all tests
npx playwright test --headed # Run with browser visible
npx playwright test --ui # Interactive UI mode
npx playwright test --debug # Debug mode with inspector
npx playwright test -g "login" # Run tests matching pattern
npx playwright codegen example.com # Generate tests by recording
npx playwright show-report # View HTML report
Best Practices
- Use role-based locators - Most resilient to DOM changes
- Avoid CSS/XPath - Brittle, break with refactoring
- Use auto-waiting assertions -
expect(locator).toBeVisible()retries - Isolate tests - Each test starts fresh, no shared state
- Mock external APIs - Use
page.route()for reliability
スコア
総合スコア
50/100
リポジトリの品質指標に基づく評価
✓SKILL.md
SKILL.mdファイルが含まれている
+20
○LICENSE
ライセンスが設定されている
0/10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
○最近の活動
3ヶ月以内に更新がある
0/10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
○タグ
1つ以上のタグが設定されている
0/5
レビュー
💬
レビュー機能は近日公開予定です