Playwright MCP サーバーを使ってテストを自動生成する (2025-10)
Playwright MCP サーバーを使ってテストを自動生成する
Playwright Test Agents と Visual Studio Code、GitHub Copilot あたりを組み合わせるイメージ?
プロジェクト準備
とりあえず Playwright を試すためのプロジェクトを作成
code:init-project
npm init playwright@latest playwright-test-agents-sandbox
npx
create-playwright playwright-test-agents-sandbox
Getting started with writing end-to-end tests with Playwright:
Initializing project in 'playwright-test-agents-sandbox'
√ Do you want to use TypeScript or JavaScript? · TypeScript
√ Where to put your end-to-end tests? · tests
√ Add a GitHub Actions workflow? (Y/n) · true
√ Install Playwright browsers (can be done manually via 'npx playwright install')? (Y/n) · true
Playwright Test Agents を Visual Studio Code (GitHub Copilot?) で使うための設定
code:init-agents
npx playwright init-agents --loop=vscode
Writing file: .github/chatmodes/🎭 generator.chatmode.md
Writing file: .github/chatmodes/🎭 healer.chatmode.md
Writing file: .github/chatmodes/ 🎭 planner.chatmode.md
Writing file: .vscode/mcp.json
Writing file: tests\seed.spec.ts
GitHub Copilot のチャットモデルと、Visual Studio Code の MCP サーバーの設定と、テストの初期化用ファイルが作られる
GitHub Copilot Chat in VS Code
MCP サーバー in VS Code
Playwright Test Agents を使ってテストを作成
まずは planner agent を使ってテストを作成
https://gyazo.com/0b89f6abff32fd561ebf0fb30ea0efc4
次に、上記で作成された Markdown をコンテキストに、generator agent でテストを生成
https://gyazo.com/3452c7db80723075d6657a5a6644b182
うまく動かないテストがある場合、healer agent で修正
https://gyazo.com/86587b994dc09275fa2268b940f6b338
便利!
参考文献
Playwright Test Agents
https://qiita.com/TMX_Saito/items/268a7b2c94ba3223b11c
Visual Studio Code に Cline をインストールして Playwright MCP を使わせる例