Skip
AgentSandbox.host

Browser testing at scale with Playwright and Selenium: setup in Python and Node.js, Docker images, Selenium Grid, parallel runs, sharding and flaky tests.

Home + Log

Playwright CLI: every command and the test options that matter

Answer first

The Playwright CLI is the npx playwright command. Its main commands are test, show-report, show-trace, codegen (record a test), install and install-deps (browsers and system packages) and merge-reports; npx playwright test takes options for filters, workers, shards, retries, traces and debugging.

Writer
Published
Updated
min
5

The Playwright CLI is the npx playwright command that comes with the @playwright/test package (in Python, the playwright command). It runs tests, records new ones, installs browsers and opens reports and traces. Every description below is quoted from Playwright's command line reference, version 1.65 (Playwright command line, read 2026-11-26), unless another source is named.

Which commands does the Playwright CLI have?

The Playwright CLI's commands for testing work are below. The reference page documents the first nine; the last three appear in npx playwright --help, which we ran with version 1.65.1 on 26 November 2026.

Table: Playwright CLI commands

CommandWhat it does
npx playwright testRuns the tests
npx playwright show-reportServes the HTML report; default port 9323
npx playwright show-trace <trace>Opens a trace in the trace viewer
npx playwright codegen <url>Opens a browser and writes test code as you click
npx playwright install [browser...]Downloads browser builds
npx playwright install-deps [browser...]Installs the operating system packages the browsers need
npx playwright uninstallRemoves browsers
npx playwright merge-reports <blob dir>Merges blob reports from shards into one report
npx playwright clear-cache"Clear all Playwright caches"
npx playwright open [url]Opens a page in a browser (help: "open page in browser specified via -b, --browser")
npx playwright screenshot <url> <filename>Captures a screenshot of a page
npx playwright pdf <url> <filename>Saves a page as PDF

Two more commands belong to agent work rather than tests: since release 1.62, "Playwright now bundles the Playwright MCP server and playwright-cli, runnable via npx playwright mcp and npx playwright cli" (Playwright release notes, read 2026-11-26).

Which npx playwright test options are used most?

These options cover most daily runs:

Table: Common npx playwright test options

OptionWhat it doesDefault
--headed"Run tests in headed browsers"headless
--ui"Run tests in interactive UI mode"off
--debug"Run tests with Playwright Inspector"off
--project <name...>Only these projects; * wildcards allowedall projects
-g, --grep <regex>Only tests matching the expression.*
-G, --grep-invert <regex>Only tests not matching itnone
--list"Collect all the tests and report them, but do not run"off
--last-failed"Only re-run the failures"off
--only-changed [ref]Only test files changed between HEAD and the ref (git)uncommitted changes
-j, --workers <n>Worker count, or a percentage of logical CPU cores50%
--shard <x/y>Run one shard, 1-based, such as 3/5no sharding
--retries <n>"Maximum retry count for flaky tests"no retries
--repeat-each <n>"Run each test N times"1
--trace <mode>on, off, on-first-retry, on-all-retries and retain modesfrom config
--timeout <ms>Per-test timeout, 0 for unlimited30 seconds
--global-timeout <ms>"Maximum time this test suite can run"unlimited
-x, --max-failures <n>Stop after the first failure, or after Noff
--reporter <name>dot, line, list, failures and otherslist locally, dot on CI
--fail-on-flaky-tests"Fail if any test is flagged as flaky"false
--forbid-only"Fail if test.only is called"false
-u, --update-snapshots [mode]Update snapshots: all, changed, missing, nonedefault
--shuffle [seed]"Schedule tests in a random order"off

Positional arguments filter by file: each is a regular expression matched against the test file's path, so npx playwright test login runs every file with "login" in its path. A file and line, npx playwright test example.spec.ts:10, runs one test (Playwright running tests, read 2026-11-26).

How do I record a test with codegen?

Run npx playwright codegen with the address of your app; a browser opens and the inspector writes code as you click. Useful options from Playwright codegen (read 2026-11-26):

npx playwright codegen demo.playwright.dev/todomvc
npx playwright codegen --viewport-size="800,600" playwright.dev
npx playwright codegen --device="iPhone 13" playwright.dev
npx playwright codegen --color-scheme=dark playwright.dev

--save-storage=auth.json saves cookies and storage after you sign in by hand, and --load-storage=auth.json starts the next session signed in. --target picks the output language, such as python, and -o writes to a file.

How do I install browsers from the CLI?

Install browsers with npx playwright install, choosing what you need (Playwright browsers, read 2026-11-26):

npx playwright install                          # the default browsers
npx playwright install --with-deps chromium     # Chromium and its system packages
npx playwright install --with-deps --only-shell # headless shell only
npx playwright install --with-deps --no-shell   # full Chromium, no headless shell

Playwright "ships a regular Chromium build for headed operations and a separate chromium headless shell for headless mode", so --only-shell saves a download when nothing runs headed. --dry-run prints what would be installed, --list shows the browsers of every Playwright installation on the machine, and npx playwright install-deps --dry-run on Linux "simulates the apt-get install" and exits non-zero if packages are missing (Playwright command line, read 2026-11-26).

Which environment variables does the CLI read?

The CLI reads several environment variables, documented across Playwright's pages:

Table: Environment variables for the Playwright CLI

VariableEffectSource
PLAYWRIGHT_BROWSERS_PATHWhere browsers are installed and looked forPlaywright browsers
PLAYWRIGHT_SKIP_BROWSER_GC=1Keep browser versions no installation uses any morePlaywright browsers
PLAYWRIGHT_DOWNLOAD_HOSTDownload browsers from your own mirrorPlaywright browsers
DEBUG=pw:browserLog browser launchesPlaywright CI
PWDEBUG=1Run with the Inspector (Python: PWDEBUG=1 pytest -s)Playwright Python running tests
PW_TEST_CONNECT_WS_ENDPOINTRun tests against a remote browser serverPlaywright Docker
PLAYWRIGHT_JSON_OUTPUT_NAMEFile name for the JSON reporterPlaywright reporters
PLAYWRIGHT_TRANSFORM_CACHE_DIRWhere transpiled tests are cachedPlaywright command line

All sources in this table were read on 2026-11-26.

What is the Python version of the CLI?

In Python the same commands are run as playwright after pip install playwright, for example playwright install --with-deps chromium, playwright codegen --target python and playwright show-trace trace.zip. Tests run through pytest instead of playwright test; see our Playwright Python setup guide.

What we read for this article

Q&A

  1. How do I run a single Playwright test from the command line?

    Pass the file and line, npx playwright test example.spec.ts:10, or a title pattern with -g, npx playwright test -g "add a todo item".

  2. How do I list Playwright tests without running them?

    Run npx playwright test --list. It collects all tests and reports them without running any.

  3. What is the default Playwright test timeout?

    30 seconds per test. Change it with --timeout in milliseconds, or the timeout option in the config. --global-timeout caps the whole run and is unlimited by default.

  4. How do I install only Chromium for Playwright?

    Run npx playwright install --with-deps chromium. For headless-only runs, npx playwright install --with-deps --only-shell installs the smaller headless shell instead of full Chromium.

  5. Is there a Playwright CLI for coding agents?

    Yes. Since release 1.62 the playwright package bundles playwright-cli and the Playwright MCP server, run as npx playwright cli and npx playwright mcp.