LinuxCommandLibrary

playwright

TLDR

Install browsers

$ npx playwright install
copy
Run tests
$ npx playwright test
copy
Run specific test
$ npx playwright test [test.spec.ts]
copy
Run with UI mode
$ npx playwright test --ui
copy
Generate code
$ npx playwright codegen [url]
copy

SYNOPSIS

playwright command [options]

DESCRIPTION

Playwright is a framework for browser automation and testing. It supports Chromium, Firefox, and WebKit with a unified API for cross-browser testing.

PARAMETERS

install

Install browsers.
test
Run tests.
codegen
Record and generate code.
show-report
Show test report.
--ui
Interactive UI mode.
--debug
Debug mode.
--headed
Show browser window.

EXAMPLES

$ # Setup new project
npm init playwright@latest

# Run all tests
npx playwright test

# Run with specific browser
npx playwright test --project=firefox

# Debug failing test
npx playwright test --debug

# Generate code by recording
npx playwright codegen example.com

# Show HTML report
npx playwright show-report
copy

TEST EXAMPLE

$ import { test, expect } from '@playwright/test';

test('basic test', async ({ page }) => {
  await page.goto('https://example.com');
  await expect(page).toHaveTitle(/Example/);
});
copy

CAVEATS

Requires Node.js. Browser binaries are large. CI may need special setup.

HISTORY

Playwright was developed by Microsoft, created by the team behind Puppeteer, released in 2020.

SEE ALSO

Copied to clipboard