Repo of the Day
microsoft/playwright
Published: Sep 9, 2022
Open repository ↗Playwright is similar to Cypress in that it allows end to end testing and is supposed to be faster. Im intrigued.
Summary
Playwright is a framework from Microsoft for automating and testing web browsers. It exposes a single API to drive Chromium, Firefox, and WebKit, and ships in several forms: a test runner, a Node library, a CLI for coding agents, an MCP server for AI agents, and a VS Code extension. The project is licensed under Apache-2.0 and is primarily written in TypeScript.
What it is useful for
The most common use case is end-to-end testing of web applications across multiple browsers without maintaining separate test suites per engine. Outside testing, the library form fits any script that needs programmatic browser control — screenshots, PDF generation, web scraping, network interception, or emulating mobile devices such as the iPhone 15 via devices['iPhone 15']. The CLI and MCP components let AI agents and coding assistants interact with pages deterministically through structured accessibility snapshots rather than vision models.
How engineers can use it
For end-to-end testing, the README documents a one-step setup:
npm init playwright@latest
Tests are written in TypeScript using role-based locators and auto-retrying assertions:
import { test, expect } from '@playwright/test';
test('has title', async ({ page }) => {
await page.goto('https://playwright.dev/');
await expect(page).toHaveTitle(/Playwright/);
});
Run them with npx playwright test — tests execute in parallel across configured browsers, and each test gets a fresh browser context for isolation.
For automation scripts without a test runner, install just the library:
npm i playwright
A minimal screenshot script launches Chromium, navigates, and captures the page:
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();
For AI-driven automation, the MCP server can be added to any MCP client with npx @playwright/mcp@latest as the command, while coding agents use the CLI installed via npm i -g @playwright/cli@latest and commands like playwright-cli open <url> --headed and playwright-cli screenshot. Authentication state can be saved once with page.context().storageState({ path: 'auth.json' }) and reused across tests, and failures can be inspected in the Trace Viewer by enabling trace: 'on-first-retry' and running npx playwright show-trace trace.zip.
Documented notes: Chromium uses Chrome for Testing rather than the stable consumer Chrome, and Python, .NET, and Java bindings are distributed separately. Configuration beyond what is shown here is not covered in the README excerpt, so refer to the official documentation for the full options reference.