Power Your Software Testing with AI Agents and Cloud
The Native AI-Agentic Cloud Platform to Supercharge Quality Engineering. Test Intelligently and Ship Faster.
- TestMu AI (Formerly LambdaTest)
- /
- Blog
- /
- Playwright CLI: All Commands + playwright-cli for AI Agents
Playwright CLI: Every Command, Plus the New playwright-cli for AI Coding Agents
Every npx playwright command with flags, plus the new playwright-cli for Claude Code and Copilot: install, commands, vs MCP, and when to skip scripts.
Published on:
Playwright 1.64.0 puts 21 subcommands under npx playwright, and npx playwright test alone takes 40 options. A second tool with nearly the same name, playwright-cli, has 100 commands of its own and is built for AI coding agents such as Claude Code.
Every command and option here comes from the --help output of Playwright 1.64.0 and @playwright/cli 0.1.22, read on 11 October 2026 and checked against the Playwright command line docs. If you are new to the framework, start with the Playwright tutorial.
What Is the Playwright CLI?
The Playwright CLI is the command-line interface you use to run, record, debug and report on Playwright tests, invoked with npx playwright. The term now also refers to playwright-cli, a separate Microsoft tool (@playwright/cli) that lets AI coding agents like Claude Code and GitHub Copilot drive a browser through short shell commands.
They solve different problems, so pick by who is at the keyboard.
| You want to | Use | Start with |
|---|---|---|
| Run, record or debug tests you write | npx playwright (Playwright Test CLI) | npm init playwright@latest, then npx playwright test |
| Let a coding agent open pages, click, fill and take screenshots | playwright-cli | npm install -g @playwright/cli@latest |
| Get a pass or fail on a user flow without maintaining a script | Kane CLI by TestMu AI | npm install -g @testmuai/kane-cli |
In Playwright 1.64.0 the test package reaches both tools. Its help output lists a cli subcommand ("run playwright cli commands from terminal") and an mcp subcommand ("run the Playwright MCP server"), and npx playwright cli --help prints the same 100 commands as the standalone package.
Versions used here, from the npm registry: @playwright/test 1.64.0, published 7 October 2026, and @playwright/cli 0.1.22, published 28 September 2026. The Playwright installation docs list Node.js 22.x, 24.x and 26.x as supported.
Playwright CLI Commands: The Complete Cheat Sheet
Every test-runner command starts with npx playwright in a Node.js project. Playwright 1.64.0 has 21 of them, and npx playwright --help prints the list.
| Command | What it does |
|---|---|
npx playwright test | Runs tests with Playwright Test. Its 40 options are in the npx playwright test section |
npx playwright codegen [url] | Opens a page and writes test code from your actions |
npx playwright install [browser...] | Downloads the browser builds this Playwright version needs |
npx playwright install-deps [browser...] | Installs the system libraries the browsers need; asks for sudo |
npx playwright uninstall | Removes the browsers this Playwright installation downloaded |
npx playwright open [url] | Opens a page in the browser chosen with -b |
npx playwright cr [url] | Opens a page in Chromium. ff and wk do the same for Firefox and WebKit |
npx playwright screenshot <url> <file> | Captures a page screenshot |
npx playwright pdf <url> <file> | Saves a page as a PDF |
npx playwright show-trace [trace] | Opens a recorded trace in the Trace Viewer |
npx playwright trace | Inspects a trace from the terminal: actions, requests, console messages, errors |
npx playwright show-report [report] | Serves the HTML report |
npx playwright merge-reports [dir] | Merges blob reports from sharded runs into one report |
npx playwright clear-cache | Clears build and test caches |
npx playwright init-agents --loop=claude | Adds the planner, generator and healer agent definitions. Loop values: claude, codex, copilot, opencode, vscode, vscode-legacy |
npx playwright init-skills | Installs Playwright agent skills; --loop takes claude (default) or agents |
npx playwright cli | Runs playwright-cli commands from the test package |
npx playwright mcp | Runs the Playwright MCP server |
npx playwright help [command] | Prints help for one command |
npx playwright --version | Prints the installed Playwright version |
The three agent definitions that init-agents writes are described in the Playwright test agents docs and walked through in the guide to Playwright Agents.
Setup and browsers
| Command | What it does |
|---|---|
npm init playwright@latest | Scaffolds a project: config file, example test and an optional GitHub Actions workflow |
npx playwright install | Installs the default browsers for the installed Playwright version |
npx playwright install chromium | Installs one browser: chromium, firefox, webkit, chromium-headless-shell, or a branded channel such as chrome or msedge |
npx playwright install --with-deps | Installs browsers and their system dependencies, the form to use in CI containers. Add a browser name to install only that one |
npx playwright install --only-shell | Installs only the headless shell when installing Chromium; --no-shell skips the shell |
npx playwright install --dry-run | Prints what would be installed without downloading |
npx playwright install --list | Lists the browsers from every Playwright installation on the machine |
npx playwright install --force | Reinstalls browsers that are already present |
npx playwright uninstall --all | Removes the browsers of every Playwright installation on the machine |
Each Playwright version needs its own browser builds, so run npx playwright install again after every upgrade. For a first-time setup on Windows, macOS or Linux, see how to install Playwright.
npx playwright test: Flags for Running Tests
npx playwright test runs every test in the configured test directory. It runs headless, uses workers equal to half of your logical CPU cores (the help text gives 50% as the --workers default), and exits with code 1 when a test fails, which fails the CI job.
Playwright 1.64.0 accepts 40 command line options here, and all 40 appear in this section or under debugging and reports. A flag on the command line overrides the same setting in playwright.config.ts: with timeout: 1 in the config a test failed with "Test timeout of 1ms exceeded", and adding --timeout=30000 to the command made it pass.
The examples use one spec, run against Playwright's TodoMVC demo:
// tests/smoke.spec.ts
import { test, expect } from '@playwright/test';
test('todo page loads', async ({ page }) => {
await page.goto('https://demo.playwright.dev/todomvc/');
await expect(page).toHaveTitle(/TodoMVC/);
});A passing run looks like this. The config sets channel: 'chrome', so the test used the Chrome already on the machine:
$ npx playwright test
Running 1 test using 1 worker
✓ 1 tests/smoke.spec.ts:3:5 › todo page loads (1.7s)
1 passed (2.5s)Choosing which tests run
| Command | What it does |
|---|---|
npx playwright test tests/login.spec.ts | Runs one file. Arguments are regular expressions matched against the file path, so a folder name or several paths also work |
npx playwright test tests/login.spec.ts:42 | Runs the test declared at line 42 |
npx playwright test -g "checkout" | Runs tests whose title matches the regular expression (--grep) |
npx playwright test -G "@slow" | Skips tests whose title matches (--grep-invert) |
npx playwright test --project=firefox | Runs the named projects from the config; * works as a wildcard |
npx playwright test --last-failed | Re-runs only the tests that failed in the previous run. --last-failed-file changes where that list is read from; the default is <outputDir>/.last-run.json |
npx playwright test --only-changed=main | Runs test files changed between HEAD and the ref; with no ref, uncommitted changes |
npx playwright test --test-list=tests.txt | Runs the tests listed in a file; --test-list-invert skips them |
npx playwright test --list | Lists the collected tests without running them |
npx playwright test --no-deps | Skips project dependencies |
npx playwright test --pass-with-no-tests | Exits 0 when no tests are found |
Controlling the run
| Command | What it does |
|---|---|
npx playwright test --headed | Shows the browser window; the default is headless |
npx playwright test --browser=webkit | Sets the browser: all, chromium, firefox or webkit (default chromium). It fails when the config defines projects, where --project does this job |
npx playwright test --workers=4 | Sets the worker count, as a number or a percentage of cores (-j 4) |
npx playwright test --fully-parallel | Runs every test in parallel, including tests in the same file |
npx playwright test --retries=2 | Retries a failing test up to two times |
npx playwright test --repeat-each=10 | Runs each test 10 times, a quick way to expose a flaky one |
npx playwright test --fail-on-flaky-tests | Fails the run when any test is flagged as flaky |
npx playwright test --shard=2/4 | Runs the second of four shards |
npx playwright test --shuffle | Runs test files in random order; pass a seed to repeat an order |
npx playwright test -x | Stops after the first failure; --max-failures=N stops after N |
npx playwright test --timeout=60000 | Sets the per-test timeout in milliseconds; the default is 30000 and 0 means unlimited |
npx playwright test --global-timeout=600000 | Caps the whole run in milliseconds |
npx playwright test --forbid-only | Fails the run if a test.only was committed |
npx playwright test -c playwright.ci.config.ts | Uses another config file (--config) |
npx playwright test --tsconfig=tsconfig.ci.json | Applies one tsconfig to all imported files |
npx playwright test --output=artifacts | Changes the artifacts folder; the default is test-results |
npx playwright test --quiet | Suppresses stdio from the tests |
npx playwright test --run-agents=missing | Runs agents to generate the code for page.perform calls; modes are missing, all and none |
--shard is how one suite gets split across CI machines. For how to set that up, see the guide to Playwright sharding.
Debugging, Traces and Reports From the Command Line
--ui, --debug and --trace are flags on npx playwright test. Traces and reports also have their own subcommands.
Debugging and traces
| Command | What it does |
|---|---|
npx playwright test --ui | Opens UI Mode: watch mode, a timeline of each step and a locator picker |
npx playwright test --ui-port=8080 | Serves UI Mode in a browser tab; --ui-host sets the host |
npx playwright test --debug | Runs with the Playwright Inspector. Shortcut for PWDEBUG=1 plus --timeout=0 --max-failures=1 --headed --workers=1 |
npx playwright test --debug=cli | Pauses the test before its first action and prints a playwright-cli attach command; the walkthrough is in the playwright-cli section |
PWDEBUG=1 npx playwright test | The environment-variable form of --debug, in bash syntax. In PowerShell set $env:PWDEBUG=1 first, in cmd set PWDEBUG=1 |
npx playwright test --trace on | Forces a tracing mode: on, off, on-first-retry, on-all-retries, retain-on-failure, retain-on-first-failure, retain-on-failure-and-retries |
npx playwright show-trace trace.zip | Opens the trace in the Trace Viewer |
npx playwright trace open trace.zip | Extracts a trace for terminal inspection; follow with trace actions, trace requests, trace console or trace errors |
npx playwright trace reads a trace without opening a window, and its install-skill command writes a SKILL.md so a coding agent can read traces the same way. For the interactive route, see the walkthrough of Playwright UI Mode.
Reports, snapshots and utilities
| Command | What it does |
|---|---|
npx playwright test --reporter=html | Picks reporters, comma-separated: list (default), line, dot, json, junit, null, github, html, blob, perfetto, coverage |
npx playwright test --add-reporter=junit | Adds a reporter on top of the ones in the config |
npx playwright show-report | Serves the last HTML report on localhost:9323; --host and --port change that |
npx playwright merge-reports --reporter html ./blob-report | Merges blob reports from sharded runs into one HTML report |
npx playwright test -u | Updates snapshots (--update-snapshots); modes are all, changed, missing and none |
npx playwright test --update-source-method=3way | Chooses how source is updated: patch (default), 3way or overwrite |
npx playwright test --ignore-snapshots | Skips screenshot and snapshot expectations |
npx playwright screenshot --full-page https://example.com page.png | Takes a screenshot without writing a test. --wait-for-selector and --wait-for-timeout delay the capture |
npx playwright pdf https://example.com page.pdf | Saves a page as a PDF; --paper-format sets the paper size |
npx playwright open https://example.com | Opens the page in a browser that Playwright controls; -b picks the browser |
npx playwright clear-cache | Clears build and test caches |
Recording Tests With npx playwright codegen
npx playwright codegen opens a browser and writes test code as you click and type. The output is a Playwright Test file unless you change --target, whose default is playwright-test.
| Command | What it does |
|---|---|
npx playwright codegen https://example.com | Opens the page and starts recording |
npx playwright codegen -o tests/new.spec.ts | Saves the generated script to a file (--output) |
npx playwright codegen --target=python | Sets the language: javascript, playwright-test, python, python-async, python-pytest, csharp, csharp-mstest, csharp-nunit, csharp-xunit, java, java-junit |
npx playwright codegen --device="iPhone 15" | Records with that device's viewport and user agent |
npx playwright codegen --save-storage=auth.json | Saves cookies and local storage when you close the browser |
npx playwright codegen --load-storage=auth.json | Starts from a saved storage state, so you are already logged in |
npx playwright codegen -b webkit | Records in another browser: cr, chromium, ff, firefox, wk, webkit |
npx playwright codegen --channel=chrome | Uses a Chromium distribution channel such as chrome, chrome-beta or msedge-dev |
npx playwright codegen --test-id-attribute=data-qa | Generates test ID selectors from that attribute |
npx playwright codegen --viewport-size="1280, 720" | Sets the viewport. Related emulation flags: --color-scheme, --geolocation, --timezone, --lang, --user-agent |
npx playwright codegen --save-har=flow.har | Saves a HAR file of the network activity; --save-har-glob filters its entries |
npx playwright codegen --ignore-https-errors | Ignores HTTPS errors. Other network and profile flags: --proxy-server, --proxy-bypass, --http-credentials, --block-service-workers, --user-data-dir, --timeout |
open and screenshot accept the same browser, device and viewport flags. For a recording walkthrough, read the guide to the Playwright recorder.
Playwright CLI in Python, Java and .NET
Python, Java and .NET reach the CLI through their own entry points. In Playwright for Python 1.60.0, playwright --help lists 13 commands: open, codegen, install, uninstall, install-deps, cr, ff, wk, screenshot, pdf, show-trace, trace and help. It has no test, show-report or merge-reports, because pytest runs the tests.
| Language | How you call the CLI |
|---|---|
| Python | playwright install and playwright codegen demo.playwright.dev/todomvc, or python -m playwright install when the script is not on PATH. Tests run through pytest: pytest --headed --browser webkit |
| Java | mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args="codegen demo.playwright.dev/todomvc" |
| .NET | pwsh bin/Debug/net8.0/playwright.ps1 install |
The Java and .NET commands are from each binding's docs on playwright.dev. In Python, the pytest-playwright plugin adds --headed and --browser to pytest, and it installs with pip install pytest-playwright playwright -U.
playwright-cli: Playwright's Command Line for AI Coding Agents
playwright-cli (@playwright/cli) is a separate Microsoft package that turns browser automation into short shell commands an AI coding agent can call, such as playwright-cli open, click and screenshot. The playwright-cli docs describe it as "token-efficient browser control through concise CLI commands and installable skills", for agents that have to fit browser work, a large codebase and reasoning into one context window.
Your test suite still runs on npx playwright test. playwright-cli is what an agent uses to explore a page and act on it.
Install playwright-cli
# global install
npm install -g @playwright/cli@latest
playwright-cli --help
# or per project
npm install -D @playwright/cli@latest
npx playwright-cli --help
# only if the machine has no Chrome, or you want another browser
playwright-cli install-browser
playwright-cli install-browser firefoxThe docs ask for Node.js 20 or newer. open uses the Chrome channel when you pass no --browser flag: on a Mac with Google Chrome installed, it launched that Chrome with no download.
Give your agent the skills
Skills are local instruction files that tell Claude Code, GitHub Copilot and similar agents which commands exist and when to use them.
# this project
playwright-cli install --skills
# every project (writes to ~/.claude/skills)
playwright-cli install --skills -g
# agents that read ~/.agents/skills
playwright-cli install --skills=agents -gThen prompt the agent in natural language, for example: Use playwright-cli to open the staging site, add two todo items and take a screenshot of the result. Without skills, the docs suggest telling the agent to read playwright-cli --help first.
If Claude Code also wrote the app, see testing apps built with Claude Code for checking it in a real browser with Kane CLI.
A real playwright-cli session
This session ran on @playwright/cli 0.1.22 on macOS on 11 October 2026, against Playwright's TodoMVC demo. The shell had PLAYWRIGHT_CLI_SESSION=blogdemo set, which names the session.
playwright-cli open https://demo.playwright.dev/todomvc/ --browser=chrome
playwright-cli snapshot
playwright-cli fill e8 "Write Playwright tests"
playwright-cli press Enter
playwright-cli snapshot
playwright-cli check e21
playwright-cli screenshot
playwright-cli closeEvery command prints what happened and the Playwright code it ran. The open command returned this:
### Browser `blogdemo` opened with pid 72532.
### Ran Playwright code
```js
await page.goto('https://demo.playwright.dev/todomvc/');
```
### Page
- Page URL: https://demo.playwright.dev/todomvc/#/
- Page Title: React • TodoMVC
### Snapshot
- [Snapshot](.playwright-cli/page-2026-10-11T13-31-43-421Z.yml)snapshot returns the page as an accessibility tree in YAML, with a short ref on every element. After the first todo was added, the input and the new item looked like this (other nodes trimmed):
- textbox "What needs to be done?" [active] [ref=e8]
- list [ref=e18]:
- listitem [ref=e19]:
- generic [ref=e20]:
- checkbox "Toggle Todo" [ref=e21]
- generic [ref=e22]: Write Playwright testsThe agent passes a ref to the next command, here check e21, and the CLI answers with the locator it resolved:
$ playwright-cli check e21
### Ran Playwright code
await page.getByRole('checkbox', { name: 'Toggle Todo' }).check();That echoed line is ordinary Playwright code, so an agent can paste it into a spec file. Per the docs, CSS and role selectors also work as targets, for example playwright-cli click "role=button[name=Submit]".
playwright-cli command reference
playwright-cli --help in 0.1.22 lists 100 commands. Put a command name after --help, as in playwright-cli --help open, to see that command's options. A target is an element ref from a snapshot, or a CSS or role selector.
| Command | What it does |
|---|---|
| Browser | |
open [url] | Opens the browser and goes to the URL if you give one |
goto <url> | Navigates to a URL |
close | Closes the browser |
attach [name] | Attaches to a running Playwright browser. --extension connects to your own browser through the Playwright extension, and --cdp takes a CDP endpoint URL |
detach | Detaches from an attached browser |
resize <w> <h> | Resizes the browser window |
delete-data | Deletes the session's data |
| Elements | |
click <target> [button] | Clicks an element |
dblclick <target> [button] | Double-clicks an element |
fill <target> <text> | Fills text into an editable element, addressed by ref or selector |
type <text> | Types on the keyboard into whichever element has focus (it runs page.keyboard.type); --submit presses Enter afterwards |
hover <target> | Hovers over an element |
select <target> <val> | Selects an option in a dropdown |
check <target> | Checks a checkbox or radio button |
uncheck <target> | Unchecks a checkbox or radio button |
drag <startTarget> <endTarget> | Drags one element onto another |
drop <target> | Drops files or data onto an element |
upload <files...> | Uploads one or more files |
dialog-accept [prompt] | Accepts a dialog |
dialog-dismiss | Dismisses a dialog |
| Reading the page | |
snapshot [target] | Captures the page snapshot that holds the element refs |
find [text] | Searches the snapshot for text or a regular expression and returns the matching nodes with context |
eval <func> [target] | Evaluates a JavaScript expression on the page or an element |
generate-locator <target> | Generates a Playwright locator for an element |
highlight [target] | Shows a highlight overlay on an element; --hide removes it |
console [min-level] | Lists console messages |
screenshot [target] | Saves a screenshot of the page or one element |
pdf | Saves the page as a PDF |
| Navigation and input | |
go-back | Goes back to the previous page |
go-forward | Goes forward to the next page |
reload | Reloads the page |
press <key> | Presses a key, such as Enter or ArrowLeft |
keydown <key> | Holds a key down |
keyup <key> | Releases a key |
mousemove <x> <y> | Moves the mouse to a position |
mousedown [button] | Presses a mouse button |
mouseup [button] | Releases a mouse button |
mousewheel <dx> <dy> | Scrolls the mouse wheel |
| Tabs | |
tab-list | Lists all tabs |
tab-new [url] | Opens a new tab |
tab-select <index> | Switches to a tab |
tab-close [index] | Closes a tab |
| Storage | |
state-save [filename] | Saves the storage (authentication) state to a file |
state-load <filename> | Loads storage state from a file |
cookie-list, cookie-get <name>, cookie-set <name> <value>, cookie-delete <name>, cookie-clear | Lists, reads, sets, deletes and clears cookies |
localstorage-list, localstorage-get <key>, localstorage-set <key> <value>, localstorage-delete <key>, localstorage-clear | The same five operations for localStorage |
sessionstorage-list, sessionstorage-get <key>, sessionstorage-set <key> <value>, sessionstorage-delete <key>, sessionstorage-clear | The same five operations for sessionStorage |
| Emulation | |
set-color-scheme <scheme> | Emulates the light or dark color scheme |
set-reduced-motion <motion> | Emulates the reduced motion preference |
set-forced-colors <colors> | Emulates forced colors mode |
set-contrast <contrast> | Emulates the preferred contrast |
set-media <media> | Emulates the CSS media type |
clear-color-scheme, clear-reduced-motion, clear-forced-colors, clear-contrast, clear-media | Clears each emulation |
| Network | |
requests | Lists the network requests since the page loaded and numbers them |
request <index> | Shows one request in full: headers, body and response |
request-headers <index> | Prints only the request headers |
request-body <index> | Prints only the request body |
response-headers <index> | Prints only the response headers |
response-body <index> | Prints the response body; binary bodies are saved to a file |
route <pattern> | Mocks network requests that match a URL pattern |
route-list | Lists the active routes |
unroute [pattern] | Removes the routes matching a pattern, or all routes |
network-state-set <state> | Sets the network state to online or offline |
| Recording and tracing | |
run-code [code] | Runs a Playwright code snippet |
recording-start | Starts recording your actions |
recording-stop | Stops recording and prints the actions as Playwright code |
tracing-start | Starts trace recording |
tracing-stop | Stops trace recording |
video-start [filename] | Starts video recording |
video-stop | Stops video recording |
video-chapter <title> | Adds a chapter marker to the video |
video-show-actions | Annotates each following action on the page with a callout that names it |
video-hide-actions | Stops annotating actions |
show | Opens the Playwright dashboard |
| Test debugging | |
pause-at <location> | Runs the attached test up to a file:line location and pauses there |
resume | Resumes the test |
step-over | Steps over the next call in the test |
| WebMCP | |
webmcp-list | Lists the WebMCP tools the page registers |
webmcp-call <name> | Calls one of those tools |
| Setup and sessions | |
install | Initializes the workspace; --skills installs the agent skills |
install-browser [browser] | Installs a browser. Takes --with-deps, --dry-run, --list, --force, --only-shell and --no-shell |
list | Lists browser sessions |
close-all | Closes all browser sessions |
kill-all | Force-kills all browser sessions, for stale or zombie processes |
| Global options | |
-s=<session> | Sends the command to a named session |
--json | Outputs the response as JSON |
--raw | Outputs only the result value, without status and code |
--help [command] | Prints help |
--version | Prints the version |
open takes --headed, --browser (chrome, firefox, webkit, msedge), --device, --mobile, --persistent, --profile, --config and --idle-timeout. The CLI runs headless unless you add --headed.
Sessions for parallel agents
Each named session is its own browser. Pass -s=name on a command or set PLAYWRIGHT_CLI_SESSION in the agent's environment, then run playwright-cli list to see what is open:
$ playwright-cli list
### Browsers
- blogdemo:
- status: open
- browser-type: chrome
- user-data-dir: <in-memory>
- headed: falseThe profile lives in memory unless you add --persistent. Per the docs, a headless session shuts itself down after an hour without commands, so a session an agent forgot to close does not keep a browser running, while headed and attached browsers stay up. playwright-cli show opens a dashboard with a live view of every session.
Debug a paused test with playwright-cli
npx playwright test --debug=cli pauses the test before its first action and prints an attach command for playwright-cli:
$ npx playwright test --debug=cli
Running 1 test using 1 worker
### The test is currently paused at the start
### Debugging Instructions
- Run "playwright-cli attach tw-64343c" to attach to this testFrom a second terminal, or from the coding agent, attach and step through. Each step prints the page state and the call the test makes next (output trimmed):
$ playwright-cli attach tw-64343c
### Session `tw-64343c` created, attached to `tw-64343c`.
Run commands with: playwright-cli -s=tw-64343c <command>
### Paused
- Navigate demo.playwright.dev/todomvc/ at tests/smoke.spec.ts:4
$ playwright-cli -s=tw-64343c step-over
### Page
- Page URL: https://demo.playwright.dev/todomvc/#/
- Page Title: React • TodoMVC
### Paused
- Expect "toHaveTitle" at tests/smoke.spec.ts:5
$ playwright-cli -s=tw-64343c resumeThe pause message says to "use any tools to explore and interact", so snapshot, eval and console work on the test's page while it waits, and pause-at tests/smoke.spec.ts:5 runs to a given line. After resume the runner finished the test and reported 1 passed. This ran on Playwright 1.64.0 with @playwright/cli 0.1.22.
npx playwright vs playwright-cli vs Playwright MCP
Use npx playwright to run tests you own, playwright-cli when a coding agent with a shell needs a browser, and Playwright MCP when the agent reaches its tools over MCP. The Playwright docs call playwright-cli best for coding agents such as Claude Code and GitHub Copilot, because CLI commands avoid loading large tool schemas and verbose accessibility trees into the model context. They call MCP best for agentic loops that benefit from persistent state and iterative reasoning over page structure.
| npx playwright | playwright-cli | Playwright MCP | |
|---|---|---|---|
| npm package on 11 October 2026 | @playwright/test 1.64.0 | @playwright/cli 0.1.22 | @playwright/mcp 0.0.83 |
| Who writes the test | You, in code | Nobody. The agent acts one command at a time | Nobody. The agent acts one tool call at a time |
| Who calls it | You or your CI job | A coding agent, through shell commands and skills | An agent, through MCP tool calls |
| What comes back | Test results, an exit code, the HTML report and traces | The result of each command, the Playwright code it ran, and snapshot and screenshot files on disk | Tool results returned to the model |
| Pass or fail verdict | Yes. The run exits 1 when a test fails | None. The agent decides what worked | None. The agent decides what worked |
| Browsers | Chromium, Firefox, WebKit and branded channels | chrome, firefox, webkit, msedge | chrome, firefox, webkit, msedge |
| Default mode | Headless | Headless | Headed; --headless switches it |
| Code it gives you | The test files are the code | Each command echoes its Playwright code, and recording-stop prints recorded actions as code | --codegen sets the language for generated code: typescript (default), python, java, csharp or none |
| Cost | Free, Apache-2.0 | Free, Apache-2.0 | Free, Apache-2.0 |
The MCP server starts with npx playwright mcp in Playwright 1.64.0, or from the @playwright/mcp package. Neither agent tool reports whether a user flow passed, so the agent ends up judging its own work.
For token cost per call against turns per task, and how each behaves in CI, read Playwright CLI vs MCP vs Kane CLI. The comparison hub is the place to compare Kane CLI with other tools.
Testing a Flow Without Writing Playwright: Kane CLI
Kane CLI is TestMu AI's agent for CLI browser testing. You give it one objective in natural language and it drives Chrome. Its product page lists typed exit codes for the result (0 pass, 1 fail, 2 setup error, 3 timeout) and export of runs to Python Playwright.
npm install -g @testmuai/kane-cli
kane-cli login
kane-cli run --url https://ecommerce-playground.lambdatest.io/ \
"search for a laptop, add the first result to the cart and verify the cart shows one item"The Kane CLI cookbook has runs that check network calls, console output, cookies and storage. The command-by-command comparison is in Playwright CLI vs Kane CLI, and other runners are in the roundup of Playwright CLI alternatives. The product page currently lists 10,000 Kane CLI credits, free for a month: Get Kane CLI.
Running npx playwright test on a Cloud
npx playwright test launches browsers on your own machine by default. To run the same suite on TestMu AI, point connectOptions at the cloud's WebSocket endpoint in the config:
// pw-cloud.config.ts
import { defineConfig } from '@playwright/test';
const capabilities = {
browserName: 'Chrome',
browserVersion: 'latest',
'LT:Options': {
platform: 'Windows 11',
build: 'playwright-cli blog check',
name: 'todo page loads',
user: process.env.LT_USERNAME,
accessKey: process.env.LT_ACCESS_KEY,
},
};
export default defineConfig({
testDir: './tests',
use: {
connectOptions: {
wsEndpoint: `wss://cdp.lambdatest.com/playwright?capabilities=${encodeURIComponent(JSON.stringify(capabilities))}`,
},
},
});The command does not change. With LT_USERNAME and LT_ACCESS_KEY exported, the same spec ran on Chrome on Windows 11 with Playwright 1.64.0 on 11 October 2026:
$ npx playwright test -c pw-cloud.config.ts
Running 1 test using 1 worker
✓ 1 tests/smoke.spec.ts:3:5 › todo page loads (1.6s)
1 passed (17.6s)The runner applies filters, sharding and the worker count before it connects, so --project, --grep, --shard and --workers behave as they do locally. The Playwright testing docs list the browser names and capabilities the cloud accepts, and HyperExecute splits a large suite into parallel tasks when one runner is too slow.
Note: Run your Playwright suite across 3,000+ browser and OS combinations on TestMu AI. See Playwright testing on TestMu AI
Playwright CLI Errors and How to Fix Them
Most Playwright CLI failures come from browser builds that do not match the installed Playwright version, missing system libraries in CI, or a filter that matches nothing. On Playwright 1.64.0 with no browsers installed, npx playwright test fails like this (output trimmed):
$ npx playwright test
Running 1 test using 1 worker
1) tests/smoke.spec.ts:3:5 › todo page loads
Error: browserType.launch: Executable doesn't exist at ~/Library/Caches/ms-playwright/chromium_headless_shell-1248/chrome-headless-shell-mac-arm64/chrome-headless-shell
Looks like Playwright was just installed or updated.
Please run the following command to download new browsers:
npx playwright install
1 failed| Error or symptom | Cause | Fix |
|---|---|---|
Executable doesn't exist at .../ms-playwright/... | No browsers installed for this Playwright version | npx playwright install, or npx playwright install --with-deps in CI |
| Tests break right after upgrading Playwright | Each version needs its own browser builds | Run npx playwright install after every upgrade |
Host system is missing dependencies | System libraries are missing in the Linux container | npx playwright install-deps, or use the official Playwright Docker image |
Error: No tests found | Wrong folder, a testDir mismatch, or a -g filter that matches nothing. The run exits 1 | Run npx playwright test --list to see what the runner collects |
Error: No tests found on a --last-failed run | Nothing failed in the previous run, so there is nothing to re-run. This also exits 1 | Add --pass-with-no-tests to the command, which makes it exit 0 |
Cannot use --browser option when configuration file defines projects | The config has a projects array | Use --project=name, or set browserName in the project |
npx: command not found | Node.js is not on PATH | Install a supported Node.js release; the docs list 22.x, 24.x and 26.x |
playwright: command not found in Python | The scripts folder of your Python environment is not on PATH, for example because the virtualenv is not activated | Run python -m playwright install, which works without the script |
Test timeout of 30000ms exceeded | A slow page, or a wait that never resolves | Raise it with --timeout=60000 while you debug, then find the stuck step with --ui or a trace |
| A test.only blocks the rest of the suite in CI | A focused test was committed | Add --forbid-only to the CI command |
| The HTML report will not open in CI | show-report starts a local server on port 9323 | Upload playwright-report/ as a build artifact and open it on your machine |
playwright-cli: command not found | The package is installed per project, not globally | Use npx playwright-cli, install with npm install -g @playwright/cli@latest, or run npx playwright cli on Playwright 1.64.0 |
| The agent ignores playwright-cli | Skills are not installed, so the agent does not know the commands | playwright-cli install --skills; add -g for every project |
Author
Parth Mistry is a Member of Technical Staff at TestMu AI, building SmartUI, the visual regression testing product. He developed and owns the SmartUI CLI, a modular TypeScript tool built on Playwright for multi-browser automation, and built the Storybook CLI for visual regression of UI components. He maintains cross-language SDKs in Python, Java, Ruby, C#, and Node.js, and engineered a Node-based visual rendering service on Kafka, Redis, MySQL, and S3. His migration of that service to an event-driven, KEDA-autoscaled architecture improved execution speed by 60% and cut annual infrastructure cost by $9,600. He also built the end-to-end SmartUI integration with KaneAI. Parth is a Google Summer of Code 2024 contributor and an alumnus of IIT Jodhpur.
Reviewer
Srinivasan Sekar is Director of Engineering at TestMu AI, where he leads engineering and open-source initiatives behind the Selenium and Appium automation grid and owns TestMu AI's MCP Server. A committer to Appium and a contributor to Selenium, WebdriverIO, Taiko, and AppiumTestDistribution, he brings over 15 years of experience in quality engineering and open-source technologies. He is the author of the Apress book 'The MCP Standard: A Developer's Guide to Building Universal AI Tools with the Model Context Protocol,' a Certified Kubernetes and Cloud Native Associate, and an international conference speaker. Before TestMu AI he spent over eight years at Thoughtworks as a Principal Consultant and Quality Architect. Srinivasan holds a B.Tech in Information Technology from Anna University.
Playwright CLI FAQs
Did you find this page helpful?
More Related Blogs
TestMu AI forEnterprise
Get access to solutions built on Enterprise
grade security, privacy, & compliance
- Advanced access controls
- Advanced data retention rules
- Advanced Local Testing
- Premium Support options
- Early access to beta features
- Private Slack Channel
- Unlimited Manual Accessibility DevTools Tests


