playwright
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePlaywright CLI Skill
Playwright CLI Skill
Drive a real browser from the terminal using . Prefer the bundled wrapper script so the CLI works even when it is not globally installed.
Treat this skill as CLI-first automation. Do not pivot to unless the user explicitly asks for test files.
playwright-cli@playwright/test使用从终端控制真实浏览器。优先使用捆绑的包装脚本,这样即使未全局安装该CLI也能运行。
将此技能视为以CLI优先的自动化工具。除非用户明确要求测试文件,否则不要转向。
playwright-cli@playwright/testPrerequisite check (required)
前置检查(必填)
Before proposing commands, check whether is available (the wrapper depends on it):
npxbash
command -v npx >/dev/null 2>&1If it is not available, pause and ask the user to install Node.js/npm (which provides ). Provide these steps verbatim:
npxbash
undefined在提供命令之前,检查是否可用(包装脚本依赖它):
npxbash
command -v npx >/dev/null 2>&1如果不可用,请暂停并要求用户安装Node.js/npm(它会提供)。请一字不差地提供以下步骤:
npxbash
undefinedVerify Node/npm are installed
验证Node/npm是否已安装
node --version
npm --version
node --version
npm --version
If missing, install Node.js/npm, then:
如果缺失,安装Node.js/npm,然后执行:
npm install -g @playwright/mcp@latest
playwright-cli --help
Once `npx` is present, proceed with the wrapper script. A global install of `playwright-cli` is optional.npm install -g @playwright/mcp@latest
playwright-cli --help
一旦`npx`可用,就可以继续使用包装脚本。全局安装`playwright-cli`是可选的。Skill path (set once)
技能路径(设置一次)
bash
export CODEX_HOME="${CODEX_HOME:-$HOME/.codex}"
export PWCLI="$CODEX_HOME/skills/playwright/scripts/playwright_cli.sh"User-scoped skills install under (default: ).
$CODEX_HOME/skills~/.codex/skillsbash
export CODEX_HOME="${CODEX_HOME:-$HOME/.codex}"
export PWCLI="$CODEX_HOME/skills/playwright/scripts/playwright_cli.sh"用户范围的技能安装在下(默认:)。
$CODEX_HOME/skills~/.codex/skillsQuick start
快速开始
Use the wrapper script:
bash
"$PWCLI" open https://playwright.dev --headed
"$PWCLI" snapshot
"$PWCLI" click e15
"$PWCLI" type "Playwright"
"$PWCLI" press Enter
"$PWCLI" screenshotIf the user prefers a global install, this is also valid:
bash
npm install -g @playwright/mcp@latest
playwright-cli --help使用包装脚本:
bash
"$PWCLI" open https://playwright.dev --headed
"$PWCLI" snapshot
"$PWCLI" click e15
"$PWCLI" type "Playwright"
"$PWCLI" press Enter
"$PWCLI" screenshot如果用户偏好全局安装,以下方式也有效:
bash
npm install -g @playwright/mcp@latest
playwright-cli --helpCore workflow
核心工作流
- Open the page.
- Snapshot to get stable element refs.
- Interact using refs from the latest snapshot.
- Re-snapshot after navigation or significant DOM changes.
- Capture artifacts (screenshot, pdf, traces) when useful.
Minimal loop:
bash
"$PWCLI" open https://example.com
"$PWCLI" snapshot
"$PWCLI" click e3
"$PWCLI" snapshot- 打开页面。
- 生成快照以获取稳定的元素引用。
- 使用最新快照中的引用进行交互。
- 在导航或DOM发生重大变化后重新生成快照。
- 在需要时捕获工件(截图、PDF、跟踪文件)。
最小循环示例:
bash
"$PWCLI" open https://example.com
"$PWCLI" snapshot
"$PWCLI" click e3
"$PWCLI" snapshotWhen to snapshot again
何时重新生成快照
Snapshot again after:
- navigation
- clicking elements that change the UI substantially
- opening/closing modals or menus
- tab switches
Refs can go stale. When a command fails due to a missing ref, snapshot again.
在以下情况后重新生成快照:
- 页面导航
- 点击会大幅改变UI的元素
- 打开/关闭模态框或菜单
- 切换标签页
引用可能会失效。当命令因引用缺失而失败时,请重新生成快照。
Recommended patterns
推荐模式
Form fill and submit
表单填写与提交
bash
"$PWCLI" open https://example.com/form
"$PWCLI" snapshot
"$PWCLI" fill e1 "user@example.com"
"$PWCLI" fill e2 "password123"
"$PWCLI" click e3
"$PWCLI" snapshotbash
"$PWCLI" open https://example.com/form
"$PWCLI" snapshot
"$PWCLI" fill e1 "user@example.com"
"$PWCLI" fill e2 "password123"
"$PWCLI" click e3
"$PWCLI" snapshotDebug a UI flow with traces
使用跟踪文件调试UI流程
bash
"$PWCLI" open https://example.com --headed
"$PWCLI" tracing-startbash
"$PWCLI" open https://example.com --headed
"$PWCLI" tracing-start...interactions...
...交互操作...
"$PWCLI" tracing-stop
undefined"$PWCLI" tracing-stop
undefinedMulti-tab work
多标签页操作
bash
"$PWCLI" tab-new https://example.com
"$PWCLI" tab-list
"$PWCLI" tab-select 0
"$PWCLI" snapshotbash
"$PWCLI" tab-new https://example.com
"$PWCLI" tab-list
"$PWCLI" tab-select 0
"$PWCLI" snapshotWrapper script
包装脚本
The wrapper script uses so the CLI can run without a global install:
npx --package @playwright/mcp playwright-clibash
"$PWCLI" --helpPrefer the wrapper unless the repository already standardizes on a global install.
包装脚本使用,因此无需全局安装即可运行该CLI:
npx --package @playwright/mcp playwright-clibash
"$PWCLI" --help除非仓库已标准化使用全局安装,否则优先使用包装脚本。
References
参考资料
Open only what you need:
- CLI command reference:
references/cli.md - Practical workflows and troubleshooting:
references/workflows.md
仅打开你需要的内容:
- CLI命令参考:
references/cli.md - 实用工作流与故障排除:
references/workflows.md
Guardrails
注意事项
- Always snapshot before referencing element ids like .
e12 - Re-snapshot when refs seem stale.
- Prefer explicit commands over and
evalunless needed.run-code - When you do not have a fresh snapshot, use placeholder refs like and say why; do not bypass refs with
eX.run-code - Use when a visual check will help.
--headed - When capturing artifacts in this repo, use and avoid introducing new top-level artifact folders.
output/playwright/ - Default to CLI commands and workflows, not Playwright test specs.
- 在引用这类元素ID之前,务必先生成快照。
e12 - 当引用似乎失效时,重新生成快照。
- 优先使用明确的命令,而非和
eval,除非必要。run-code - 当你没有最新快照时,使用这类占位符引用并说明原因;不要使用
eX绕过引用。run-code - 当需要视觉检查时,使用参数。
--headed - 在此仓库中捕获工件时,请使用,避免引入新的顶级工件文件夹。
output/playwright/ - 默认使用CLI命令和工作流,而非Playwright测试规范。