playwright、puppeteer、selenium-webdriver はすべてブラウザの自動操作を可能にするnpmパッケージであり、主にエンドツーエンド(E2E)テストやスクレイピング、自動化タスクに使われます。これらはそれぞれ異なるアプローチでブラウザ制御を実現しており、サポートするブラウザ範囲、API設計、安定性、デバッグ機能などに明確な違いがあります。
フロントエンド開発者がE2Eテストやブラウザ自動化を実装する際、playwright、puppeteer、selenium-webdriver の3つが代表的な選択肢になります。これらは目的こそ似ていますが、設計思想や実装方法、サポート範囲に大きな違いがあります。現場で実際に使う観点から、深く掘り下げて比較します。
puppeteer は Chromium系のみ をサポートします。つまり、ChromeやMicrosoft Edge(Chromium版)は動作しますが、FirefoxやSafariは対象外です。
// puppeteer: Chromium系限定
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
playwright は Chromium、Firefox、WebKit(Safariのエンジン)の3つを公式サポート しています。1つのテストコードで複数ブラウザでの動作確認が可能です。
// playwright: ブラウザごとに起動可能
const { chromium, firefox, webkit } = require('playwright');
const browser = await chromium.launch(); // または firefox.launch(), webkit.launch()
const page = await browser.newPage();
await page.goto('https://example.com');
selenium-webdriver は理論上 すべてのWebDriver準拠ブラウザ をサポートしますが、各ブラウザ用のドライバー(chromedriver、geckodriverなど)を別途インストール・管理する必要があります。
// selenium-webdriver: ドライバー依存
const { Builder, By } = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
let driver = await new Builder()
.forBrowser('chrome')
.setChromeOptions(new chrome.Options())
.build();
await driver.get('https://example.com');
💡 実務では、FirefoxやSafariでの動作検証が必要なら
playwright一択。Chromium系だけで十分ならpuppeteerの軽さが魅力。レガシー環境やマルチ言語対応が必須ならselenium-webdriverを検討。
puppeteer と playwright はどちらもモダンで一貫性のあるPromiseベースのAPIを持ち、page.click() や page.fill() のように直感的に操作できます。
// puppeteer
await page.goto('https://example.com');
await page.type('#username', 'testuser');
await page.click('#submit');
// playwright
await page.goto('https://example.com');
await page.fill('#username', 'testuser');
await page.click('#submit');
一方、selenium-webdriver はWebDriverプロトコルに忠実なため、要素の取得と操作が分かれており、コードが冗長になりがちです。
// selenium-webdriver
await driver.get('https://example.com');
let username = await driver.findElement(By.id('username'));
await username.sendKeys('testuser');
let submit = await driver.findElement(By.id('submit'));
await submit.click();
また、selenium-webdriver は非同期処理を async/await で書くこともできますが、内部でコマンドキューを管理するため、エラーハンドリングやデバッグがやや複雑です。
不安定なE2Eテストの最大の原因は「タイミング」です。各ツールはこの問題に対し、異なるアプローチを取っています。
puppeteer は page.waitForSelector() や page.waitForFunction() を使って明示的に待機する必要があります。
// puppeteer: 手動待機
await page.click('#load-data');
await page.waitForSelector('#result'); // 要素が表示されるまで待つ
playwright は多くのアクション(click、fill など)に 自動待機機能 が組み込まれており、要素が操作可能になるまで内部で待機します。
// playwright: 自動待機
await page.click('#load-data');
await page.click('#result'); // 要素がクリック可能になるまで自動で待つ
selenium-webdriver は WebDriverWait のような明示的待機(Explicit Wait)を推奨しており、Implicit Wait(暗黙的待機)は非推奨です。
// selenium-webdriver: 明示的待機
const until = require('selenium-webdriver/until');
await driver.findElement(By.id('load-data')).click();
await driver.wait(until.elementLocated(By.id('result')), 5000);
💡 実務では、
playwrightの自動待機がテストの安定性を大幅に向上させ、メンテナンスコストを削減します。puppeteerやselenium-webdriverでは待機ロジックの記述漏れがバグの温床になりやすいです。
モバイル端末や低速ネットワーク下での動作確認が必要な場合、ツール間でサポート状況が大きく異なります。
playwright はビルドインで デバイスエミュレーション と ネットワークスロットリング をサポートしています。
// playwright: デバイスエミュレーション
const { devices } = require('playwright');
const iPhone = devices['iPhone 13'];
const context = await browser.newContext({ ...iPhone });
const page = await context.newPage();
// playwright: ネットワーク制限
await context.setOffline(true);
await context.setGeolocation({ latitude: 35.6895, longitude: 139.6917 });
puppeteer もChromiumの機能を活用して同様のことが可能ですが、設定がやや低レベルです。
// puppeteer: ネットワーク制限
const client = await page.target().createCDPSession();
await client.send('Network.emulateNetworkConditions', {
offline: false,
latency: 100,
downloadThroughput: 1.5 * 1024 * 1024 / 8,
uploadThroughput: 1.5 * 1024 * 1024 / 8
});
selenium-webdriver は標準ではこれらの機能を提供せず、ブラウザ固有の拡張(例:Chrome DevTools Protocol経由)を使う必要があります。そのため、設定が複雑でポータビリティが低いです。
playwright は PWDEBUG=1 環境変数でGUI付きデバッガーを起動でき、タイムトラベルデバッグやスクリーンショット比較も可能です。
PWDEBUG=1 npm test
puppeteer は headless: false オプションでブラウザを可視化できますが、高度なデバッグ機能は備えていません。
// puppeteer: 可視化
const browser = await puppeteer.launch({ headless: false });
selenium-webdriver も同様にヘッドフルモードで実行可能ですが、デバッグ支援機能は最小限です。
puppeteer と playwright は npm install 時に必要なブラウザバイナリを自動でダウンロードします。追加設定不要で即座に使い始められます。
npm install playwright
# → Chromium, Firefox, WebKit が自動インストール
selenium-webdriver はブラウザドライバーを別途管理する必要があります。たとえばChromeを使うには chromedriver をインストールし、PATHを通すか、コード内でパスを指定する必要があります。
// selenium-webdriver: ドライバーの明示的指定
const service = new chrome.ServiceBuilder('/path/to/chromedriver').build();
chrome.setDefaultService(service);
これはCI環境でのセットアップを煩雑にし、チーム内での環境差異を生む原因になります。
2024年現在、いずれのパッケージも 非推奨ではありません。puppeteer はGoogleが、playwright はMicrosoftが、selenium-webdriver はSeleniumプロジェクトがそれぞれ積極的にメンテナンスしています。
ただし、puppeteer は2023年にコミュニティ主導のプロジェクトとなり、Googleによる直接的な開発は終了しました。一方、playwright は活発な開発が続いており、新機能(例:Component Testing、Trace Viewer)が継続的に追加されています。
| 観点 | playwright | puppeteer | selenium-webdriver |
|---|---|---|---|
| サポートブラウザ | Chromium, Firefox, WebKit | Chromium系のみ | 全WebDriver準拠ブラウザ(ドライバー要) |
| APIの使いやすさ | 非常に直感的(自動待機付き) | 直感的だが手動待機必要 | 冗長(要素取得と操作が分離) |
| モバイル/ネットワークエミュレート | ビルドインで簡単 | 可能だが低レベル | 標準では不可、ブラウザ依存 |
| デバッグ支援 | GUIデバッガー、トレース機能 | ヘッドフルモードのみ | 最小限 |
| セットアップの手間 | 自動(npm installで完了) | 自動 | ドライバー管理が必要 |
| 最適なユースケース | 本格的なE2Eテスト、クロスブラウザ検証 | スクレイピング、Chromium限定の自動化 | マルチ言語環境、既存Seleniumインフラとの統合 |
playwright を試すべきです。安定性、機能、開発体験のすべてで現代的なニーズに応えています。puppeteer も有効。特にスクレイピングやPDF生成など、テスト以外の自動化タスクに向いています。selenium-webdriver は、既にSeleniumエコシステムに投資している組織や、複数言語でテストを統一したい場合に限って検討してください。純粋なNode.jsプロジェクトではオーバーヘッドが大きすぎます。これらのツールは「どれが絶対に優れている」というより、「どんな課題を解決したいか」によって最適解が変わります。あなたのチームの技術スタック、テスト要件、保守コストを見極めて、賢く選んでください。
playwright を選ぶべきなのは、複数のブラウザ(Chromium、Firefox、WebKit)でのテストが必要な場合、または最新のWeb標準やモバイルエミュレーション、ネットワーク条件のシミュレーションといった高度な機能を活用したいときです。特に大規模なE2EテストスイートやCI/CD環境での安定した実行を求めるプロジェクトに適しています。
puppeteer を選ぶべきなのは、Chromium系ブラウザ(ChromeやEdge)のみを対象とし、シンプルで軽量な自動化スクリプトやスクレイピングを実装したい場合です。Playwrightほどの多機能さは不要で、既存のNode.js環境に手軽に組み込みたいケースに向いています。
selenium-webdriver を選ぶべきなのは、JavaやPythonなど複数の言語環境で同じテストコードを共有したい場合、あるいは既にSelenium Gridなどのインフラを運用している組織において、JavaScriptベースのテストも統合したいときです。ただし、Node.js専用のユースケースでは他の2つより冗長になることが多いです。
Playwright is a framework for web automation and testing. It drives Chromium, Firefox, and WebKit with a single API — in your tests, in your scripts, and as a tool for AI agents.
Choose the path that fits your workflow:
| Best for | Install | |
|---|---|---|
| Playwright Test | End-to-end testing | npm init playwright@latest |
| Playwright CLI | Coding agents (Claude Code, Copilot) | npm i -g @playwright/cli@latest |
| Playwright MCP | AI agents and LLM-driven automation | npx @playwright/mcp@latest |
| Playwright Library | Browser automation scripts | npm i playwright |
| VS Code Extension | Test authoring and debugging in VS Code | Install from Marketplace |
Playwright Test is a full-featured test runner built for end-to-end testing. It runs tests across Chromium, Firefox, and WebKit with full browser isolation, auto-waiting, and web-first assertions.
npm init playwright@latest
Or add manually:
npm i -D @playwright/test
npx playwright install
import { test, expect } from '@playwright/test';
test('has title', async ({ page }) => {
await page.goto('https://playwright.dev/');
await expect(page).toHaveTitle(/Playwright/);
});
test('get started link', async ({ page }) => {
await page.goto('https://playwright.dev/');
await page.getByRole('link', { name: 'Get started' }).click();
await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible();
});
npx playwright test
Tests run in parallel across all configured browsers, in headless mode by default. Each test gets a fresh browser context — full isolation with near-zero overhead.
Auto-wait and web-first assertions. No artificial timeouts. Playwright waits for elements to be actionable, and assertions automatically retry until conditions are met.
Locators. Find elements with resilient locators that mirror how users see the page:
page.getByRole('button', { name: 'Submit' })
page.getByLabel('Email')
page.getByPlaceholder('Search...')
page.getByTestId('login-form')
Test isolation. Each test runs in its own browser context — equivalent to a fresh browser profile. Save authentication state once and reuse it across tests:
// Save state after login
await page.context().storageState({ path: 'auth.json' });
// Reuse in other tests
test.use({ storageState: 'auth.json' });
Tracing. Capture execution traces, screenshots, and videos on failure. Inspect every action, DOM snapshot, network request, and console message in the Trace Viewer:
// playwright.config.ts
export default defineConfig({
use: {
trace: 'on-first-retry',
},
});
npx playwright show-trace trace.zip
Parallelism. Tests run in parallel by default across all configured browsers.
Playwright CLI is a command-line interface for browser automation designed for coding agents. It's more token-efficient than MCP — commands avoid loading large tool schemas and accessibility trees into the model context.
npm install -g @playwright/cli@latest
Optionally install skills for richer agent integration:
playwright-cli install --skills
Point your coding agent at a task:
Test the "add todo" flow on https://demo.playwright.dev/todomvc using playwright-cli.
Take screenshots for all successful and failing scenarios.
Or run commands directly:
playwright-cli open https://demo.playwright.dev/todomvc/ --headed
playwright-cli type "Buy groceries"
playwright-cli press Enter
playwright-cli screenshot
Use playwright-cli show to open a visual dashboard with live screencast previews of all running browser sessions. Click any session to zoom in and take remote control.
playwright-cli show
Full CLI documentation | GitHub
The Playwright MCP server gives AI agents full browser control through the Model Context Protocol. Agents interact with pages using structured accessibility snapshots — no vision models or screenshots required.
Add to your MCP client (VS Code, Cursor, Claude Desktop, Windsurf, etc.):
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": ["@playwright/mcp@latest"]
}
}
}
One-click install for VS Code:
For Claude Code:
claude mcp add playwright npx @playwright/mcp@latest
Ask your AI assistant to interact with any web page:
Navigate to https://demo.playwright.dev/todomvc and add a few todo items.
The agent sees the page as a structured accessibility tree:
- heading "todos" [level=1]
- textbox "What needs to be done?" [ref=e5]
- listitem:
- checkbox "Toggle Todo" [ref=e10]
- text: "Buy groceries"
It uses element refs like e5 and e10 to click, type, and interact — deterministically and without visual ambiguity. Tools cover navigation, form filling, screenshots, network mocking, storage management, and more.
Full MCP documentation | GitHub
Use playwright as a library for browser automation scripts — web scraping, PDF generation, screenshot capture, and any workflow that needs programmatic browser control without a test runner.
npm i playwright
Take a screenshot:
import { chromium } from 'playwright';
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('https://playwright.dev/');
await page.screenshot({ path: 'screenshot.png' });
await browser.close();
Generate a PDF:
import { chromium } from 'playwright';
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('https://playwright.dev/');
await page.pdf({ path: 'page.pdf', format: 'A4' });
await browser.close();
Emulate a mobile device:
import { chromium, devices } from 'playwright';
const browser = await chromium.launch();
const context = await browser.newContext(devices['iPhone 15']);
const page = await context.newPage();
await page.goto('https://playwright.dev/');
await page.screenshot({ path: 'mobile.png' });
await browser.close();
Intercept network requests:
import { chromium } from 'playwright';
const browser = await chromium.launch();
const page = await browser.newPage();
await page.route('**/*.{png,jpg,jpeg}', route => route.abort());
await page.goto('https://playwright.dev/');
await browser.close();
Library documentation | API reference
The Playwright VS Code extension brings test running, debugging, and code generation directly into your editor.
Run and debug tests from the editor with a single click. Set breakpoints, inspect variables, and step through test execution with a live browser view.
Generate tests with CodeGen. Click "Record new" to open a browser — navigate and interact with your app while Playwright writes the test code for you.
Pick locators. Hover over any element in the browser to see the best available locator, then click to copy it to your clipboard.
Trace Viewer integration. Enable "Show Trace Viewer" in the sidebar to get a full execution trace after each test run — DOM snapshots, network requests, console logs, and screenshots at every step.
Install the extension | VS Code guide
| Linux | macOS | Windows | |
|---|---|---|---|
| Chromium1 148.0.7778.96 | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| WebKit 26.4 | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Firefox 150.0.2 | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Headless and headed execution on all platforms. 1 Uses Chrome for Testing by default.
Playwright is also available for Python, .NET, and Java.