claude-skills/

Anthropic公式スキル・プラグインの日本語ディレクトリ

last sync 22h ago
スキルSkills

🧪webapp-testing

プラグイン
example-skills
ライセンス
Complete terms in LICENSE.txt

説明

ローカルWebアプリケーションとのインタラクションおよびテストをPlaywrightを使用して行うためのツールキット。 フロントエンド機能の検証、UIの動作デバッグ、ブラウザスクリーンショットのキャプチャ、 ブラウザログの確認をサポートします。

原文を表示

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.

ユースケース

  • フロントエンド機能を検証するとき
  • UIの動作をデバッグするとき
  • ブラウザスクリーンショットをキャプチャするとき
  • ブラウザログを確認するとき

本文(日本語訳)

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') # 重要: JavaScriptの実行完了まで待機
    # ... 自動化ロジックをここに記述
    browser.close()

事前調査してから操作するパターン

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

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

  3. 特定したセレクターを使ってアクションを実行する

よくある落とし穴

NG: 動的アプリで networkidle を待たずにDOMを検査する ✅ OK: 検査の前に 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 — 自動化実行中のコンソールログのキャプチャ
原文(English)を表示

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

原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。