playwright
Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
Top Related Projects
JavaScript API for Chrome and Firefox
Fast, easy and reliable testing for anything that runs in a browser.
A browser automation framework and ecosystem.
Next-gen browser and mobile automation test framework for Node.js
Cross-platform automation framework for all kinds of apps, built on top of the W3C WebDriver protocol
Quick Overview
Playwright is a powerful automation library for web testing and scraping, developed by Microsoft. It provides a single API to automate Chromium, Firefox, and WebKit browsers, enabling cross-browser web automation that is reliable and fast.
Pros
- Cross-browser support (Chromium, Firefox, WebKit) with a single API
- Fast and reliable automation with auto-wait functionality
- Powerful tools for debugging and tracing
- Supports multiple programming languages (JavaScript, TypeScript, Python, .NET, Java)
Cons
- Steeper learning curve compared to some other automation tools
- Larger package size due to bundled browser binaries
- May require more system resources than lighter alternatives
- Limited support for older browser versions
Code Examples
- Basic page navigation and screenshot:
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
await page.screenshot({ path: 'screenshot.png' });
await browser.close();
})();
- Interacting with page elements:
const { firefox } = require('playwright');
(async () => {
const browser = await firefox.launch();
const page = await browser.newPage();
await page.goto('https://example.com/login');
await page.fill('input[name="username"]', 'myuser');
await page.fill('input[name="password"]', 'mypassword');
await page.click('button[type="submit"]');
await browser.close();
})();
- Handling multiple pages:
const { webkit } = require('playwright');
(async () => {
const browser = await webkit.launch();
const context = await browser.newContext();
const page1 = await context.newPage();
const page2 = await context.newPage();
await page1.goto('https://example.com');
await page2.goto('https://another-example.com');
// Interact with both pages...
await browser.close();
})();
Getting Started
To get started with Playwright, follow these steps:
- Install Playwright:
npm init playwright@latest
- Create a new test file (e.g.,
example.spec.js):
const { test, expect } = require('@playwright/test');
test('basic test', async ({ page }) => {
await page.goto('https://playwright.dev/');
const title = page.locator('.navbar__inner .navbar__title');
await expect(title).toHaveText('Playwright');
});
- Run the test:
npx playwright test
This will install Playwright, create a basic test, and run it across all supported browsers.
Competitor Comparisons
JavaScript API for Chrome and Firefox
Pros of Puppeteer
- Mature ecosystem with extensive documentation and community support
- Native integration with Chrome DevTools Protocol
- Simpler setup for projects primarily targeting Chrome/Chromium
Cons of Puppeteer
- Limited cross-browser support (primarily Chrome/Chromium)
- Slower test execution compared to Playwright
- Less comprehensive API for handling modern web features
Code Comparison
Puppeteer:
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
await page.screenshot({path: 'screenshot.png'});
await browser.close();
Playwright:
const browser = await playwright.chromium.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
await page.screenshot({path: 'screenshot.png'});
await browser.close();
Both Puppeteer and Playwright are powerful tools for browser automation and testing. Puppeteer excels in Chrome-specific scenarios and has a more established ecosystem. Playwright offers better cross-browser support, faster execution, and a more comprehensive API for modern web applications. The code structure is similar, making it relatively easy to migrate between the two if needed.
Fast, easy and reliable testing for anything that runs in a browser.
Pros of Cypress
- Easier setup and configuration, with a more user-friendly interface
- Built-in time travel and debugging features
- Strong community support and extensive documentation
Cons of Cypress
- Limited cross-browser testing capabilities (primarily focused on Chrome)
- Slower test execution compared to Playwright
- Less flexibility in handling iframes and multiple tabs
Code Comparison
Cypress:
describe('Login', () => {
it('should log in successfully', () => {
cy.visit('/login')
cy.get('#username').type('user@example.com')
cy.get('#password').type('password123')
cy.get('button[type="submit"]').click()
cy.url().should('include', '/dashboard')
})
})
Playwright:
test('should log in successfully', async ({ page }) => {
await page.goto('/login')
await page.fill('#username', 'user@example.com')
await page.fill('#password', 'password123')
await page.click('button[type="submit"]')
await expect(page).toHaveURL(/.*dashboard/)
})
Both frameworks offer similar syntax for common testing scenarios, but Playwright uses async/await for better control flow. Cypress provides a more chainable API, while Playwright offers a more flexible and powerful approach to handling asynchronous operations.
A browser automation framework and ecosystem.
Pros of Selenium
- Wider language support (Java, Python, C#, Ruby, JavaScript, etc.)
- Larger community and ecosystem with extensive third-party tools and resources
- Better suited for legacy browser testing (IE, older versions)
Cons of Selenium
- Slower test execution compared to Playwright
- More complex setup and configuration
- Less robust handling of modern web features (shadow DOM, iframes)
Code Comparison
Selenium (Python):
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get("https://example.com")
element = driver.find_element(By.ID, "my-element")
element.click()
Playwright (Python):
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch()
page = browser.new_page()
page.goto("https://example.com")
page.click("#my-element")
Both Selenium and Playwright are popular choices for browser automation and testing. Selenium has been around longer and offers broader language support, while Playwright provides better performance and easier handling of modern web technologies. The choice between the two depends on specific project requirements and team preferences.
Next-gen browser and mobile automation test framework for Node.js
Pros of WebdriverIO
- Supports a wider range of browsers and devices, including mobile platforms
- More extensive ecosystem with numerous plugins and integrations
- Longer history and larger community, potentially leading to better support
Cons of WebdriverIO
- Steeper learning curve, especially for beginners
- Slower test execution compared to Playwright
- More complex setup and configuration process
Code Comparison
WebdriverIO:
describe('My Login application', () => {
it('should login with valid credentials', async () => {
await browser.url('https://example.com/login');
await $('#username').setValue('myuser');
await $('#password').setValue('mypassword');
await $('button[type="submit"]').click();
await expect($('#logged-in-message')).toBeExisting();
});
});
Playwright:
test('should login with valid credentials', async ({ page }) => {
await page.goto('https://example.com/login');
await page.fill('#username', 'myuser');
await page.fill('#password', 'mypassword');
await page.click('button[type="submit"]');
await expect(page.locator('#logged-in-message')).toBeVisible();
});
Both WebdriverIO and Playwright are powerful tools for automated testing, with Playwright offering a more modern and streamlined approach, while WebdriverIO provides broader compatibility and a rich ecosystem. The choice between them depends on specific project requirements and team preferences.
Cross-platform automation framework for all kinds of apps, built on top of the W3C WebDriver protocol
Pros of Appium
- Supports a wider range of mobile platforms, including iOS, Android, and Windows
- Allows testing of native, hybrid, and mobile web applications
- Uses standard WebDriver protocol, making it easier for those familiar with Selenium
Cons of Appium
- Generally slower test execution compared to Playwright
- More complex setup and configuration process
- Less robust support for modern web technologies and features
Code Comparison
Appium (JavaScript):
const driver = await wdio.remote(capabilities);
await driver.setImplicitTimeout(5000);
await driver.$('~myButton').click();
await driver.deleteSession();
Playwright (JavaScript):
const browser = await playwright.chromium.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
await page.click('button');
await browser.close();
While both frameworks allow for automated testing, Playwright's API is more modern and concise, focusing on web technologies. Appium's API is geared towards mobile testing and uses a different set of commands and selectors.
Playwright offers better performance and easier setup for web testing, while Appium excels in cross-platform mobile testing scenarios. The choice between the two depends on the specific testing requirements and target platforms of the project.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
ð Playwright
Documentation | API reference
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.
Get Started
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
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.
Install
npm init playwright@latest
Or add manually:
npm i -D @playwright/test
npx playwright install
Write a test
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();
});
Run tests
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.
Key capabilities
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
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.
Install
npm install -g @playwright/cli@latest
Optionally install skills for richer agent integration:
playwright-cli install --skills
Usage
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
Session monitoring
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
Playwright MCP
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.
Setup
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
How it works
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
Playwright Library
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.
Install
npm i playwright
Examples
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
VS Code Extension
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
Cross-Browser Support
| Linux | macOS | Windows | |
|---|---|---|---|
| Chromium1 149.0.7827.3 | :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.
Other Languages
Playwright is also available for Python, .NET, and Java.
Resources
Top Related Projects
JavaScript API for Chrome and Firefox
Fast, easy and reliable testing for anything that runs in a browser.
A browser automation framework and ecosystem.
Next-gen browser and mobile automation test framework for Node.js
Cross-platform automation framework for all kinds of apps, built on top of the W3C WebDriver protocol
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot