ワンクリックで
e2e
E2E test generation skill using Playwright CLI with Page Object Model pattern and visual regression testing via @visual tag.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
E2E test generation skill using Playwright CLI with Page Object Model pattern and visual regression testing via @visual tag.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
| name | e2e |
| description | E2E test generation skill using Playwright CLI with Page Object Model pattern and visual regression testing via @visual tag. |
This skill generates E2E tests using playwright-cli commands for browser automation. It uses the Page Object Model pattern and supports visual regression testing with the @visual tag in test titles.
Use this skill when:
@visual tag)npm install -g @playwright/cli@latest)1. EXPLORE → Navigate to URL, take snapshot, understand the page structure
2. PLAN → Identify testable features and create test plan
3. GENERATE PAGES → Create Page Object classes
4. GENERATE TESTS → Create test specs (add @visual tag for visual checks)
5. VALIDATE → Run tests to ensure they pass
For detailed exploration techniques and CLI commands, see:
mockApi utility for deterministic testsFor code templates and patterns, see:
@visual tag for visual testingOpen URL
playwright-cli open https://example.com
Take Page Snapshot
playwright-cli snapshot
Identify Interactive Elements from snapshot output:
Test Interactions before generating code:
playwright-cli click e12
playwright-cli snapshot # Verify result
Based on exploration, identify:
@visual tag to test title when needed)See examples/page-object-model.md for templates.
Key rules:
readonly class propertieswaitFor before action.catch(() => false) for visibility checksSee examples/e2e-tests.md for templates.
Key patterns:
@visual tag to test title for visual regression tests (e.g., 'should display page correctly @visual')__tests__/
├── e2e/
│ ├── pages/ # Page Object classes (ALL locators & interaction logic)
│ │ └── [page-name]-page.ts
│ └── [feature].spec.ts # Integration tests (include @visual tag for visual checks)
└── constants/ # Test data only (URLs, emails, text values)
└── test-data.ts
Important Notes:
@visual tagNever use full-page screenshots. Component-level screenshots are more stable and focused:
// CORRECT - Component-level screenshot
await expect(featurePage.header).toHaveScreenshot('preview-mode-header.png');
await expect(featurePage.globalStylesPanel).toHaveScreenshot('styles-expanded.png');
// WRONG - Full-page screenshot (too fragile)
await expect(page).toHaveScreenshot('preview-mode.png');
| Full Page | Component |
|---|---|
| Fails when ANY element changes | Only fails when the specific component changes |
| Large image files | Small, focused images |
| Hard to diagnose failures | Easy to see what changed |
| Flaky due to animations | Stable, isolated scope |
In playwright.config.ts, use strict comparison (no tolerance):
expect: {
toHaveScreenshot: {
maxDiffPixels: 0, // Strict - no pixel difference allowed
},
},
// In your Page Object class constructor
this.header = page.locator('.guido__header, header').first();
this.globalStylesPanel = page.getByRole('tabpanel', { name: 'General Styles' });
this.leftSidebar = page.locator('.left-sidebar, [class*="sidebar"]').first();
Use descriptive names that indicate the component and state:
// Good names
await expect(featurePage.header).toHaveScreenshot('header-preview-mode.png');
await expect(featurePage.globalStylesPanel).toHaveScreenshot('styles-mobile-view.png');
// Bad names (too generic)
await expect(element).toHaveScreenshot('test1.png');
For deterministic tests, mock API responses using the mockApi utility:
import { API_ENDPOINTS } from '../enums/constants';
import { mockApi } from '../mockServer';
test('displays empty state @visual', async ({ page }) => {
// Setup mocks BEFORE navigation
await mockApi(page, `**/${API_ENDPOINTS.LIST_DATA}**`, 'list-data/empty.json');
const featurePage = new FeaturePage(page);
await featurePage.goto('/page');
await expect(featurePage.emptyState).toHaveScreenshot('empty-state.png');
});
See references/api-mocking.md for full documentation.
playwright-cli snapshot before writing any codemockApi utility for deterministic test data@visual tag in title - e.g., 'component visual test @visual'maxDiffPixels: 0 in configpage.waitForTimeout() - Use proper waitFor conditions instead| Error | Solution |
|---|---|
| Element not found | Take new snapshot, verify ref value |
| Timeout on navigation | Increase timeout or check URL |
| Screenshot mismatch | Update baseline with --update-snapshots |
| Network errors | Check console messages and network requests |
Example CI/CD workflow for E2E tests with sharding and visual regression:
name: E2E Tests
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
push:
branches: [develop]
workflow_dispatch:
inputs:
update_snapshots:
description: 'Update snapshots only'
required: false
default: 'false'
type: boolean
jobs:
run-e2e-tests:
if: github.event_name == 'workflow_dispatch' || github.event_name == 'pull_request' || github.event_name == 'push'
timeout-minutes: 60
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
shardIndex: [1, 2, 3, 4]
shardTotal: [4]
permissions:
contents: read
issues: write
pull-requests: write
env:
APP_URL: https://localhost:3000
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- name: Install dependencies
run: npm ci
- name: Install Playwright browsers
run: npx playwright install --with-deps
- name: Start dev server
run: |
npm run dev &
npx wait-on ${{ env.APP_URL }}
- name: Run E2E Tests
run: |
if [ "${{ inputs.update_snapshots }}" == "true" ]; then
npx playwright test --grep @visual --update-snapshots --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }} --reporter=blob
else
npx playwright test --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }} --reporter=blob
fi
- name: Upload blob report
if: always()
uses: actions/upload-artifact@v4
with:
name: blob-report-${{ github.run_id }}-${{ matrix.shardIndex }}
path: blob-report/
retention-days: 3
merge-reports:
if: always()
needs: [run-e2e-tests]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- name: Install dependencies
run: npm ci
- name: Download blob reports
uses: actions/download-artifact@v4
with:
path: all-blob-reports
pattern: blob-report-${{ github.run_id }}-*
merge-multiple: true
- name: Merge reports
run: npx playwright merge-reports --reporter html ./all-blob-reports
- name: Upload HTML report
uses: actions/upload-artifact@v4
with:
name: playwright-report
path: playwright-report/
retention-days: 7
| Feature | Description |
|---|---|
| Sharding | Tests split across 4 parallel runners for speed |
| Visual update | workflow_dispatch with update_snapshots input to update baselines |
| Blob reports | Each shard uploads blob report for later merging |
| Report merging | Combined HTML report from all shards |
| grep @visual | Only visual tests updated when update_snapshots is true |