jpskill.com
🛠️ 開発・MCP Anthropic公式 🔴 エンジニア向け 👤 エンジニア・AI開発者

🧪 PlaywrightでWebアプリ自動テスト

webapp-testing

Playwright を使って Web アプリを自動操作・テスト・スクショ取得するSkill。

⏱ ライブラリ調査+組込 半日 → 1時間

📺 まず動画で見る(YouTube)

▶ 【衝撃】最強のAIエージェント「Claude Code」の最新機能・使い方・プログラミングをAIで効率化する超実践術を解説! ↗

※ jpskill.com 編集部が参考用に選んだ動画です。動画の内容と Skill の挙動は厳密には一致しないことがあります。

📜 元の英語説明(参考)

Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.

🇯🇵 日本人クリエイター向け解説

一言でいうと

Playwright を使って Web アプリを自動操作・テスト・スクショ取得するSkill。

日本人がよく使う場面
・自社サイトの主要導線を毎日自動チェック ・障害発生時の状況スクショ自動収集 ・コンペサイトの定点観測 ・QA エンジニア不在チームの回帰テスト

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-17
取得日時
2026-05-17
同梱ファイル
3

💬 こう話しかけるだけ — サンプルプロンプト

  • PlaywrightでWebアプリ自動テスト を使って、最小構成のサンプルコードを示して
  • PlaywrightでWebアプリ自動テスト の主な使い方と注意点を教えて
  • PlaywrightでWebアプリ自動テスト を既存プロジェクトに組み込む方法を教えて

これをClaude Code に貼るだけで、このSkillが自動発動します。

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

Webアプリケーションのテスト

ローカルのWebアプリケーションをテストするには、ネイティブPythonのPlaywrightスクリプトを作成します。

利用可能なヘルパースクリプト:

  • scripts/with_server.py - サーバーのライフサイクルを管理します(複数のサーバーをサポートします)

スクリプトを実行する際は、まず必ず--helpを付けて使用法を確認してください。カスタマイズされたソリューションが絶対に必要だと判明するまで、ソースコードを読まないでください。これらのスクリプトは非常に大きく、コンテキストウィンドウを汚染する可能性があります。これらは、コンテキストウィンドウに取り込まれるのではなく、ブラックボックススクリプトとして直接呼び出されることを目的としています。

意思決定ツリー: アプローチの選択

ユーザーのタスク → 静的HTMLですか?
    ├─ はい → HTMLファイルを直接読み込んでセレクターを特定する
    │         ├─ 成功 → セレクターを使用してPlaywrightスクリプトを作成する
    │         └─ 失敗/不完全 → 動的として扱う(下記)
    │
    └─ いいえ(動的Webアプリ) → サーバーはすでに実行中ですか?
        ├─ いいえ → 実行: python scripts/with_server.py --help
        │        その後、ヘルパーを使用し、簡略化されたPlaywrightスクリプトを作成する
        │
        └─ はい → 偵察-実行:
            1. ナビゲートしてnetworkidleを待つ
            2. スクリーンショットを撮るかDOMを検査する
            3. レンダリングされた状態からセレクターを特定する
            4. 発見されたセレクターでアクションを実行する

例: with_server.pyの使用

サーバーを起動するには、まず--helpを実行し、その後ヘルパーを使用します。

単一サーバー:

python scripts/with_server.py --server "npm run dev" --port 5173 -- python your_automation.py

複数サーバー(例: バックエンド + フロントエンド):

python scripts/with_server.py \
  --server "cd backend && python server.py" --port 3000 \
  --server "cd frontend && npm run dev" --port 5173 \
  -- python your_automation.py

自動化スクリプトを作成するには、Playwrightロジックのみを含めます(サーバーは自動的に管理されます)。

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch(headless=True) # 常にChromiumをヘッドレスモードで起動します
    page = browser.new_page()
    page.goto('http://localhost:5173') # サーバーはすでに実行中で準備ができています
    page.wait_for_load_state('networkidle') # CRITICAL: JSの実行を待ちます
    # ... あなたの自動化ロジック
    browser.close()

偵察-実行パターン

  1. レンダリングされたDOMを検査する:

    page.screenshot(path='/tmp/inspect.png', full_page=True)
    content = page.content()
    page.locator('button').all()
  2. 検査結果からセレクターを特定する

  3. 発見されたセレクターを使用してアクションを実行する

よくある落とし穴

❌ 動的アプリでnetworkidleを待つ前にDOMを検査しないでください ✅ 検査する前にpage.wait_for_load_state('networkidle')を待つようにしてください

ベストプラクティス

  • バンドルされたスクリプトをブラックボックスとして使用する - タスクを達成するために、scripts/で利用可能なスクリプトのいずれかが役立つかどうかを検討してください。これらのスクリプトは、コンテキストウィンドウを散らかすことなく、一般的で複雑なワークフローを確実に処理します。--helpを使用して使用法を確認し、直接呼び出してください。
  • 同期スクリプトにはsync_playwright()を使用してください
  • 完了したら常にブラウザを閉じてください
  • text=, role=, CSSセレクター、またはIDなど、記述的なセレクターを使用してください
  • 適切な待機を追加してください: page.wait_for_selector()またはpage.wait_for_timeout()

参照ファイル

  • examples/ - 一般的なパターンを示す例:
    • element_discovery.py - ページ上のボタン、リンク、入力の発見
    • static_html_automation.py - ローカルHTMLにfile:// URLを使用する
    • console_logging.py - 自動化中のコンソールログのキャプチャ
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

Web Application Testing

To test local web applications, write native Python Playwright scripts.

Helper Scripts Available:

  • scripts/with_server.py - Manages server lifecycle (supports multiple servers)

Always run scripts with --help first to see usage. DO NOT read the source until you try running the script first and find that a customized solution is abslutely necessary. These scripts can be very large and thus pollute your context window. They exist to be called directly as black-box scripts rather than ingested into your context window.

Decision Tree: Choosing Your Approach

User task → Is it static HTML?
    ├─ Yes → Read HTML file directly to identify selectors
    │         ├─ Success → Write Playwright script using selectors
    │         └─ Fails/Incomplete → Treat as dynamic (below)
    │
    └─ No (dynamic webapp) → Is the server already running?
        ├─ No → Run: python scripts/with_server.py --help
        │        Then use the helper + write simplified Playwright script
        │
        └─ Yes → Reconnaissance-then-action:
            1. Navigate and wait for networkidle
            2. Take screenshot or inspect DOM
            3. Identify selectors from rendered state
            4. Execute actions with discovered selectors

Example: Using with_server.py

To start a server, run --help first, then use the helper:

Single server:

python scripts/with_server.py --server "npm run dev" --port 5173 -- python your_automation.py

Multiple servers (e.g., backend + frontend):

python scripts/with_server.py \
  --server "cd backend && python server.py" --port 3000 \
  --server "cd frontend && npm run dev" --port 5173 \
  -- python your_automation.py

To create an automation script, include only Playwright logic (servers are managed automatically):

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch(headless=True) # Always launch chromium in headless mode
    page = browser.new_page()
    page.goto('http://localhost:5173') # Server already running and ready
    page.wait_for_load_state('networkidle') # CRITICAL: Wait for JS to execute
    # ... your automation logic
    browser.close()

Reconnaissance-Then-Action Pattern

  1. Inspect rendered DOM:

    page.screenshot(path='/tmp/inspect.png', full_page=True)
    content = page.content()
    page.locator('button').all()
  2. Identify selectors from inspection results

  3. Execute actions using discovered selectors

Common Pitfall

Don't inspect the DOM before waiting for networkidle on dynamic apps ✅ Do wait for page.wait_for_load_state('networkidle') before inspection

Best Practices

  • Use bundled scripts as black boxes - To accomplish a task, consider whether one of the scripts available in scripts/ can help. These scripts handle common, complex workflows reliably without cluttering the context window. Use --help to see usage, then invoke directly.
  • Use sync_playwright() for synchronous scripts
  • Always close the browser when done
  • Use descriptive selectors: text=, role=, CSS selectors, or IDs
  • Add appropriate waits: page.wait_for_selector() or page.wait_for_timeout()

Reference Files

  • examples/ - Examples showing common patterns:
    • element_discovery.py - Discovering buttons, links, and inputs on a page
    • static_html_automation.py - Using file:// URLs for local HTML
    • console_logging.py - Capturing console logs during automation

同梱ファイル

※ ZIPに含まれるファイル一覧。`SKILL.md` 本体に加え、参考資料・サンプル・スクリプトが入っている場合があります。