playwright-cli

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Playwright CLI

Playwright CLI

Terminal-based browser automation using
npx playwright
. This skill covers the CLI surface: running tests, generating test code via
codegen
, taking screenshots/PDFs, and CI sharding flags.
基于终端的浏览器自动化工具,使用
npx playwright
。本技能涵盖CLI层面的操作:运行测试、通过
codegen
生成测试代码、截取屏幕截图/生成PDF,以及CI分片参数。

Scope boundary

范围边界

I want to...Use
Run E2E tests
npx playwright test
(this skill)
Record a browser session → test code
npx playwright codegen
(this skill)
One-off screenshot / PDF from a URL
npx playwright screenshot
/
pdf
(this skill)
Write / review / tune a Playwright test suite
playwright-test
skill
Agent-driven real-time browser control (navigate → click → read → assert)
mcp__claude-in-chrome__*
tools (not this skill)
Interactive data scraping / SPA exploration
claude-in-chrome
MCP tools or a Playwright script executed via
npx playwright test
For data scraping / SPA flows where you need to programmatically navigate, click "Load More", extract DOM, and save JSON: write a
tests/*.spec.ts
and run
npx playwright test
. See
playwright-test
skill for the test-authoring patterns.
我想要...使用方案
运行E2E测试
npx playwright test
(本技能)
录制浏览器会话→生成测试代码
npx playwright codegen
(本技能)
从URL一次性截取屏幕截图/生成PDF
npx playwright screenshot
/
pdf
(本技能)
编写/审阅/调整Playwright测试套件
playwright-test
技能
由Agent驱动的实时浏览器控制(导航→点击→读取→断言)
mcp__claude-in-chrome__*
工具(非本技能)
交互式数据爬取/SPA探索
claude-in-chrome
MCP工具或通过
npx playwright test
执行的Playwright脚本
对于需要程序化导航、点击“加载更多”、提取DOM并保存JSON的数据爬取/SPA流程:编写
tests/*.spec.ts
文件并运行
npx playwright test
。有关测试编写模式,请查看
playwright-test
技能。

Quick Reference

快速参考

bash
undefined
bash
undefined

Interactive codegen (generates test code from browser actions)

Interactive codegen (generates test code from browser actions)

npx playwright codegen https://example.com
npx playwright codegen https://example.com

Run all tests

Run all tests

npx playwright test
npx playwright test

Run specific file

Run specific file

npx playwright test tests/login.spec.ts
npx playwright test tests/login.spec.ts

Run specific test by title

Run specific test by title

npx playwright test -g "should login"
npx playwright test -g "should login"

Debug mode (opens Playwright Inspector)

Debug mode (opens Playwright Inspector)

npx playwright test --debug
npx playwright test --debug

UI mode (visual test runner with time-travel)

UI mode (visual test runner with time-travel)

npx playwright test --ui
npx playwright test --ui

Headed mode (see the browser)

Headed mode (see the browser)

npx playwright test --headed
npx playwright test --headed

Specific browser

Specific browser

npx playwright test --project=chromium
npx playwright test --project=chromium

Generate trace

Generate trace

npx playwright test --trace on
npx playwright test --trace on

View report

View report

npx playwright show-report
npx playwright show-report

Install browsers

Install browsers

npx playwright install npx playwright install chromium --with-deps # CI-optimized
undefined
npx playwright install npx playwright install chromium --with-deps # CI-optimized
undefined

Sharding for CI

CI分片

bash
npx playwright test --shard=1/3
npx playwright test --shard=2/3
npx playwright test --shard=3/3
bash
npx playwright test --shard=1/3
npx playwright test --shard=2/3
npx playwright test --shard=3/3

Screenshot / PDF

屏幕截图/PDF

bash
undefined
bash
undefined

Screenshot from CLI

Screenshot from CLI

npx playwright screenshot --browser=chromium https://example.com screenshot.png
npx playwright screenshot --browser=chromium https://example.com screenshot.png

PDF (Chromium only)

PDF (Chromium only)

npx playwright pdf https://example.com page.pdf
undefined
npx playwright pdf https://example.com page.pdf
undefined