playwright, puppeteer, and selenium-webdriver are libraries designed for browser automation, enabling tasks like end-to-end testing, scraping, and screenshot generation. robot3 differs significantly as it is a lightweight finite state machine library for managing internal application logic rather than controlling external browsers. While the first three interact with the DOM and network from the outside, robot3 helps structure state transitions within the frontend code itself.
When building robust frontend systems, you often need tools to control browsers for testing or to manage complex internal state. playwright, puppeteer, and selenium-webdriver handle browser automation, while robot3 manages application logic. Understanding their distinct roles prevents architectural mismatches. Let's compare how they initialize, handle logic, and manage errors.
Setting up these tools varies based on whether they control a browser or manage memory state.
playwright uses a test runner or manual browser launch.
playwright.config.ts.// playwright: Manual launch
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch();
const page = await browser.newPage();
})();
puppeteer launches a Chrome instance directly.
// puppeteer: Launch Chrome
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
})();
selenium-webdriver requires building a driver instance.
// selenium-webdriver: Build driver
const { Builder, Browser } = require('selenium-webdriver');
(async function example() {
let driver = await new Builder().forBrowser(Browser.CHROME).build();
})();
robot3 initializes a state machine in memory.
// robot3: Create machine
import { machine, service, state } from 'robot3';
const toggleMachine = machine({
inactive: state({
on: { TOGGLE: 'active' }
}),
active: state({
on: { TOGGLE: 'inactive' }
})
});
Automation tools wait for network or DOM events. State machines transition based on events.
playwright auto-waits for elements to be actionable.
// playwright: Auto-waiting
await page.click('#submit-button');
// Waits for element to be visible and enabled
puppeteer requires explicit wait commands.
// puppeteer: Explicit wait
await page.waitForSelector('#submit-button');
await page.click('#submit-button');
selenium-webdriver uses WebDriverWait for conditions.
// selenium-webdriver: Explicit wait
const until = require('selenium-webdriver').until;
await driver.wait(until.elementLocated(By.id('submit-button')));
robot3 transitions state synchronously or via integration.
// robot3: Transition state
const svc = service(toggleMachine, () => {});
svc.send('TOGGLE');
// State changes immediately in memory
Failures in automation stop tests. Failures in state machines should be predictable.
playwright captures traces and screenshots on failure.
// playwright: Test with retry
test('submit form', async ({ page }) => {
await page.goto('/form');
// Auto-retries on failure if configured
});
puppeteer throws standard Node.js errors.
// puppeteer: Manual error handling
try {
await page.click('#missing-element');
} catch (err) {
console.error('Click failed', err);
}
selenium-webdriver throws WebDriverError exceptions.
// selenium-webdriver: Try/Finally
try {
await driver.findElement(By.id('missing'));
} catch (e) {
console.error('Element not found');
} finally {
await driver.quit();
}
robot3 guards invalid transitions.
// robot3: Invalid transition
// Sending 'CLOSE' when only 'TOGGLE' is allowed
svc.send('CLOSE');
// Machine ignores invalid event safely
You need to verify a checkout flow across Chrome, Firefox, and Safari.
playwright// playwright: Multi-browser test
const { webkit, firefox, chromium } = require('playwright');
// Same test code runs on all three
You need to render a dynamic invoice page to PDF server-side.
puppeteer// puppeteer: PDF generation
await page.pdf({ path: 'invoice.pdf', format: 'A4' });
Your company has an existing Selenium Grid with custom drivers.
selenium-webdriver// selenium-webdriver: Remote grid
let driver = await new Builder()
.usingServer('http://grid-url:4444/wd/hub')
.build();
You are building a media player with play, pause, load, and error states.
robot3// robot3: State guard
const playerMachine = machine({
stopped: state({ on: { PLAY: 'playing' } }),
playing: state({ on: { PAUSE: 'paused' } })
});
| Feature | playwright | puppeteer | selenium-webdriver | robot3 |
|---|---|---|---|---|
| Primary Use | E2E Testing | Browser Control | Legacy Automation | State Logic |
| Browser Support | Chromium, Firefox, WebKit | Chromium (mostly) | All (via drivers) | None (In-memory) |
| Auto-Waiting | ✅ Built-in | ❌ Manual | ❌ Manual | N/A |
| Setup Complexity | Low | Low | High | Low |
| Language | JS/TS, Python, etc. | JS/TS | Multiple | JS/TS |
For modern browser automation, playwright offers the best developer experience with cross-browser support and stability. Use puppeteer if you need deep Chrome-specific features like PDF generation or extension testing. Stick with selenium-webdriver only if you must maintain legacy infrastructure or require specific browser drivers not supported by newer tools.
Keep robot3 separate from your testing stack. Use it inside your application code to manage complex component states. Mixing testing tools with state management libraries leads to confusion — keep your test automation external and your state logic internal.
Choose playwright for modern end-to-end testing requiring cross-browser support including WebKit, Firefox, and Chromium. It offers auto-waiting mechanisms and powerful tracing tools that reduce flaky tests. This package is ideal for teams wanting a robust, all-in-one testing solution with minimal configuration.
Choose puppeteer when your work focuses primarily on Chrome or Chromium-based environments. It provides deep access to the Chrome DevTools Protocol for advanced debugging, PDF generation, or scraping tasks. This tool fits well for projects that need tight integration with Chrome-specific features.
Choose robot3 when you need to manage complex UI state logic within your application code rather than testing it. It is suitable for components with many distinct states, like wizards or media players, where clear transitions prevent bugs. Use this for internal architecture, not for browser automation or testing.
Choose selenium-webdriver if you require support for legacy browsers or need to integrate with an existing Selenium Grid infrastructure. It offers broad language support and stability for long-standing enterprise test suites. This package is best for teams maintaining older systems or requiring specific driver configurations.
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.