‹ 首页

playwright-cli

@lexler · 收录于 昨天 · 上游提交 1 周前

Drive a browser from the terminal with playwright-cli: snapshot the page, then act on elements by ref. Use when automating browser interactions, filling web forms, testing UIs, or driving logged-in web apps from the command line.

适合你,如果你想用命令行驱动浏览器完成测试或自动化任务

/ 通过 npx 安装 校验哈希
npx oh-my-skill add lexler/skill-factory/playwright-cli
/ 通过 bash 安装
curl -fsSL https://oh-my-skill.com/install.sh | bash -s -- lexler/skill-factory/playwright-cli
/ 已经装过?验证本机副本,不用重装
npx oh-my-skill verify lexler/skill-factory/playwright-cli
安装目标可用 --agent / --scope 或 --to 明确指定;省略时只会在唯一已存在的 agent 目录上自动选择,零命中或多命中会停止并提示。content_hash 缺失或不一致均拒装。
223GitHub stars
~686最小装载
~1.3K含声明引用
~1.3K文本包总量
索引托管

怎么用

商店整理自技能原文 · 版本 2eae60e · 表述以原文为准
它做什么

装上后,你可以通过终端使用 playwright-cli 驱动浏览器:对页面进行快照,然后通过引用(ref)对元素进行操作,如点击、填写、选择等。

什么时候触发

当需要自动化浏览器交互、填写网页表单、测试 UI 或从命令行驱动已登录的 Web 应用时触发。

装好后可以这样说
指导使用 ref 或者 getByRole 定位。
技能原文 SKILL.md作者撰写 · Apache-2.0 · 2eae60e

STARTER_CHARACTER = 🎭

playwright-cli

Driving a browser from the shell. Each command prints the executed Playwright code, the page state, and a fresh snapshot.

The loop

Snapshot to see the page, act on an element by its ref, snapshot again.

playwright-cli snapshot          # accessibility tree with [ref=e8] handles
playwright-cli click e8          # act on a ref
playwright-cli snapshot          # confirm the result

Refs are not stable. Any DOM change renumbers them — re-snapshot before acting on a page that just changed. Acting on a stale ref hits the wrong element or none.

For a large page, snapshot a region instead of the whole tree: snapshot e34 or snapshot --depth=4.

Targeting elements

A target is one of three things — a ref, a CSS selector, or a Playwright locator:

playwright-cli click e8
playwright-cli click ".todo-list .toggle"
playwright-cli click "getByRole('button', { name: 'Submit' })"
playwright-cli click "getByText('buy milk')"

A bare descriptive phrase is not a target. click "the submit button" is parsed as a CSS selector and fails with "does not match any elements". Prefer refs; reach for getByRole/getByText when a ref won't survive a re-render.

Key commands
playwright-cli goto https://example.com
playwright-cli fill e5 "user@example.com" --submit   # clear, type, then Enter — one step
playwright-cli type "free text into the focused element"
playwright-cli press Enter                            # also: Tab, Escape, ArrowDown
playwright-cli select e9 "option-value"
playwright-cli check e12        # uncheck / hover / dblclick likewise
playwright-cli screenshot       # saves to .playwright-cli/

fill works on React/controlled inputs where raw DOM events don't. After filling, the field must blur before dependent values (totals, validation) update — --submit or a following press Tab does that.

Inspecting and verifying
playwright-cli eval "el => el.getAttribute('data-testid')" e5   # attributes the snapshot hides
playwright-cli console                                          # page console messages
playwright-cli requests                                         # network log, then `request <n>`

--raw strips the wrapper so output pipes, and proves what an action changed:

playwright-cli --raw snapshot > before.yml
playwright-cli click e8
playwright-cli --raw snapshot > after.yml
diff before.yml after.yml
Sessions

open launches a fresh browser; --persistent keeps cookies across runs. To drive an already-running, logged-in browser instead, attach over CDP. See [references/attaching-to-chrome.md](references/attaching-to-chrome.md).

Name parallel browsers with -s=<name> (omit it for the implicit default session). playwright-cli list, close, close-all.

Full command set

The above is the working subset. The CLI ships its own exhaustive reference — tabs, storage, mocking, tracing, video, codegen. See [references/full-command-reference.md](references/full-command-reference.md).

按 Apache-2.0 许可原样转载,未经改动 · 在 GitHub 查看 →

评论

登录即可评论;带「已验证安装」的,是发布者名下有本店的安装或持有记录。