mcpField
P
playwright-testing

playwright-testing

github.com/laurigatesテスト・品質5999 回インストール今日更新
リポジトリ

playwright-testing について

Playwright Testingは、Playwrightによるエンドツーエンドのブラウザーテストに取り組むコーディングエージェント向けのスキルです。クロスブラウザやモバイル表示、ビジュアル回帰テストに加え、設定、テスト作成、実行、デバッグを扱います。

主な機能

  1. 01Chromium、Firefox、WebKitを対象
  2. 02エンドツーエンドテストの作成を案内
  3. 03ネットワークモックとビジュアル回帰に対応
  4. 04実行・デバッグ・レポートのコマンドを提供
  5. 05モバイル表示と並列実行に対応

活用シーン

  1. 01Webアプリのログインフローを検証
  2. 02複数ブラウザーでE2Eテストを実行
  3. 03モバイル表示でのページ動作をテスト
  4. 04失敗したテストを調査してレポートを確認

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/laurigates/claude-plugins --skill playwright-testing

インストール後、Claude Code で/playwright-testingを入力して読み込まれたか確認します。

同梱ファイルREFERENCE.md

詳細

Playwright テスト

Playwright は、Web アプリケーション向けの最新のエンドツーエンドテストフレームワークです。優れた開発者体験とともに、信頼性が高く高速なクロスブラウザテストを提供します。

このスキルを使う場面

次の場合にこのスキルを使います…次の場合は別のスキルを使います…
E2E ブラウザーテストを書く単体テストを書く場合(vitest-testing を使います)
Chromium、Firefox、WebKit を対象にテストするPython コードをテストする場合(python-testing を使います)
ビジュアルリグレッションテストを設定するテスト品質を分析する場合(test-quality-analysis を使います)
E2E テストでネットワークリクエストをモックするプロパティベーステストを生成する場合(property-based-testing を使います)
モバイルのビューポートをテストするAPI コントラクトのみをテストする場合(api-testing を使います)

主な専門分野

  • クロスブラウザ:Chromium、Firefox、WebKit(Safari)でテストできます
  • 信頼性:自動待機、自動再試行により、不安定なテストを防ぎます
  • 高速:並列実行、ブラウザーコンテキストの分離に対応します
  • モダン:TypeScript を第一に設計し、async/await と自動補完に対応します
  • マルチプラットフォーム:Windows、macOS、Linux に対応します

インストール

bun create playwright                  # Initialize (recommended)
bun add --dev @playwright/test         # Or install manually
bunx playwright install                # Install browsers
bunx playwright install --with-deps    # With system deps (Linux)
bunx playwright --version              # Verify

設定(playwright.config.ts)

import { defineConfig, devices } from '@playwright/test';

export default defineConfig({
  testDir: './tests',
  timeout: 30000,
  use: {
    baseURL: 'http://localhost:3000',
    trace: 'on-first-retry',
  },
  projects: [
    {
      name: 'chromium',
      use: { ...devices['Desktop Chrome'] },
    },
  ],
});

基本的なコマンド

bunx playwright test                           # Run all tests
bunx playwright test tests/login.spec.ts       # Specific file
bunx playwright test --headed                  # See browser
bunx playwright test --debug                   # Debug mode
bunx playwright test --project=chromium        # Specific browser
bunx playwright test --ui                      # UI mode
bunx playwright codegen http://localhost:3000  # Record tests
bunx playwright show-report                    # Last report
bunx playwright show-trace trace.zip           # Trace viewer
bunx playwright test --update-snapshots        # Update snapshots

テストの作成

基本的なテスト構造
import { test, expect } from '@playwright/test';

test('basic test', async ({ page }) => {
  await page.goto('https://example.com');
  await expect(page).toHaveTitle(/Example/);
});

test.describe('login flow', () => {
  test('should login successfully', async ({ page }) => {
    await page.goto('/login');
    await page.fill('input[name="email"]', '[email protected]');
    await page.fill('input[name="password"]', 'password123');
    await page.click('button[type="submit"]');
    await expect(page).toHaveURL('/dashboard');
  });
});
セレクターとロケーター
// Text/Role selectors (recommended)
await page.getByText('Sign in').click();
await page.getByRole('button', { name: 'Submit' }).click();
await page.getByLabel('Email').fill('[email protected]');
await page.getByPlaceholder('Enter your name').fill('John');
await page.getByTestId('login-button').click();

// CSS/XPath selectors
await page.locator('.button-primary').click();
await page.locator('xpath=//button[text()="Submit"]').click();

// Chaining
await page.locator('.card').filter({ hasText: 'Product' }).getByRole('button').click();
主なアサーション
アサーション説明
toHaveTitle(title)ページタイトル
toHaveURL(url)ページ URL
toBeVisible()要素が表示されている
toBeEnabled()要素が有効になっている
toHaveText(text)要素のテキスト
toContainText(text)テキストの一部
toHaveAttribute(name, value)属性の値
toHaveClass(class)CSS クラス
toHaveValue(value)入力値
toBeEmpty()入力欄が空
toHaveCount(n)要素数
not.toBeDisabled()否定

エージェント向けの最適化

コンテキストコマンド
テストをすばやく実行bunx playwright test --reporter=line --bail
CI テストbunx playwright test --reporter=github
単一ブラウザーbunx playwright test --project=chromium --reporter=line
失敗をデバッグbunx playwright test --trace on --reporter=line
ブラウザー表示でデバッグbunx playwright test --headed --debug

詳しい例、高度なパターン、ベストプラクティスについては、REFERENCE.md を参照してください。

GPU のない CI ランナーで WebGL アプリ(CesiumJS、three.js、MapLibre)をテストする場合は、GPU のない CI での WebGL アプリを参照してください。SwiftShader のフラグ、lhci の chromeFlags 文字列に関する注意点、フレームレートの上限設定について説明しています。

参考資料

コメント