simple-skills 1.8.3 → 1.8.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -87,7 +87,6 @@ rm -rf ~/.claude/skills # 若当初装了这份
87
87
  | [officedocs](./skills/engineering/officedocs/SKILL.md) | 处理 Microsoft Office 三件套:Word(.docx)、PowerPoint(.pptx)、Excel(.xlsx)——创建、读取、编辑、提取、转换与清理 |
88
88
  | [pdf](./skills/engineering/pdf/SKILL.md) | 处理 PDF 的一切操作:读取/提取、合并、拆分、旋转、水印、表单、加密解密、OCR |
89
89
  | [performance](./skills/engineering/performance/SKILL.md) | 性能分析与优化:成本估算 → 剖析定位 → 优化技术目录 → 微基准验证 |
90
- | [playwright-cli](./skills/engineering/playwright-cli/SKILL.md) | 用 playwright-cli 自动化浏览器交互、测试网页并生成测试代码 |
91
90
  | [skill-creator](./skills/engineering/skill-creator/SKILL.md) | 创建、迭代改进 skill,并用 eval 与方差分析基准衡量性能 |
92
91
  | [skill-translator](./skills/engineering/skill-translator/SKILL.md) | 批量翻译 skills 目录或文档树到目标语言,生成结构一致的副本并执行技能精简 |
93
92
  | [verification-before-completion](./skills/engineering/verification-before-completion/SKILL.md) | 宣称完成或修复前必须运行验证命令,始终用证据支撑断言 |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "simple-skills",
3
- "version": "1.8.3",
3
+ "version": "1.8.5",
4
4
  "description": "简洁有效的 agent skills",
5
5
  "bin": {
6
6
  "simple-skills": "scripts/install.mjs"
@@ -5,63 +5,22 @@ description: 沿两个轴评审某个固定点(commit、branch、tag 或 merge
5
5
 
6
6
  # Code Review
7
7
 
8
- 派遣代码审查子代理,排查正确性缺陷(correctness bugs)和高风险代码模式(risky patterns),在问题扩散之前发现它们。审查者获得的是精心组织的评估汇报。
8
+ 对固定点与 `HEAD` 之间的 diff 做双轴评审:
9
9
 
10
- 对 `HEAD` 与用户提供的固定点之间的 diff 做双轴评审:
11
-
12
- - **Standards** — 代码是否符合本 repo 文档化的编码规范?
10
+ - **Standards** — 代码是否符合本 repo 文档化的编码规范,以及 Fowler 坏味道基线?
13
11
  - **Spec** — 代码是否忠实实现了发起 issue / spec 的要求?
14
12
 
15
- 两个轴都以**并行 sub-agent** 运行,以免互相污染上下文,然后由本 skill 汇总它们的发现。
16
-
17
-
18
- **核心原则:** 早审查,勤审查。
19
-
20
- ## 检查内容
21
-
22
- 包括但不限于:
23
-
24
- **计划对齐:**
25
- - 实现是否匹配计划 / 需求?
26
- - 偏差是有道理的改进,还是有问题的偏离?
27
- - 计划中的所有功能都到位了吗?
28
-
29
- **代码质量:**
30
- - 关注点分离清晰吗?
31
- - 错误处理到位吗?
32
- - 该有类型安全的地方有吗?
33
- - DRY 但没有过早抽象?
34
- - 边界情况处理了吗?
35
-
36
- **架构:**
37
- - 设计决策合理吗?
38
- - 可扩展性和性能合理吗?
39
- - 有没有安全隐患?
40
- - 与周围代码集成是否干净?
41
-
42
- **测试:**
43
- - 测试验证的是真实行为,不是 mock?
44
- - 边界情况覆盖了吗?
45
- - 该有集成测试的地方有吗?
46
- - 所有测试都通过吗?
47
-
48
- **生产就绪:**
49
- - 如果改了 schema,有迁移策略吗?
50
- - 考虑了向后兼容吗?
51
- - 文档完整吗?
52
- - 没有明显 bug?
13
+ 两个轴以**并行 sub-agent** 运行,以免互相污染上下文,最后由本 skill 汇总。
53
14
 
54
15
  ## 流程
55
16
 
56
17
  ### 1. 钉住固定点
57
18
 
58
- 用户指定的就是固定点——commit SHA、分支名、tag、`main`、`HEAD~5` 等等。
59
- 如果没指定,审查范围就是当前完成的任务或进行中的变更。
60
- 如果不存在进行中的任务,就问。
19
+ 用户指定的就是固定点——commit SHA、分支名、tag、`main`、`HEAD~5` 等等。如果没指定,审查范围就是当前完成的任务或进行中的变更;如果不存在进行中的任务,就问。
61
20
 
62
21
  把 diff 命令一次性记录下来:`git diff <fixed-point>...HEAD`(三点语法,即与 merge-base 比较)。同时用 `git log <fixed-point>..HEAD --oneline` 记下提交列表。
63
22
 
64
- 在继续之前,确认固定点可解析(`git rev-parse <fixed-point>`)且 diff 非空。坏引用或空 diff 应当在这里就失败——而不是在两个并行 sub-agent 内部才失败。
23
+ 在继续之前,确认固定点可解析(`git rev-parse <fixed-point>`)且 diff 非空。坏引用或空 diff 在这里失败,而不是等到两个并行 sub-agent 内部才失败。
65
24
 
66
25
  ### 2. 确定 spec 来源
67
26
 
@@ -70,7 +29,7 @@ description: 沿两个轴评审某个固定点(commit、branch、tag 或 merge
70
29
  1. 提交信息中的 issue 引用(`#123`、`Closes #45`、GitLab `!67` 等)——按 `docs/agents/issue-tracker.md` 中的工作流抓取。
71
30
  2. 用户作为参数传入的路径。
72
31
  3. `docs/changes/<capability-path>/` 下与分支名或功能匹配的变更文档(如 `spec.md`、`plans.md`)。
73
- 4. 如果都找不到,问用户 spec 在哪。如果用户说没有 spec,**Spec** sub-agent 将跳过并报告 "no spec available"。
32
+ 4. 如果都找不到,问用户 spec 在哪。用户说没有 spec 时,**Spec** sub-agent 就跳过并报告 "no spec available"。
74
33
 
75
34
  ### 3. 确定规范来源
76
35
 
@@ -79,35 +38,35 @@ repo 中任何记录「代码应该怎么写」的文档,如 `CODING_STANDARDS
79
38
  在 repo 文档之上,Standards 轴永远携带下面的**坏味道基线(smell baseline)**——一组固定的 Fowler 代码坏味道(《重构》第 3 章),即使 repo 什么都没写也适用。它受两条规则约束:
80
39
 
81
40
  - **repo 规范优先。** 文档化的 repo 规范永远胜出;当它认可了基线会标记的东西时,压制该坏味道。
82
- - **永远是判断题。** 每个坏味道都是带标签的启发式("possible Feature Envy"),绝不是硬性违规——并且和这里的任何规范一样,工具已经强制的事一律跳过。
83
-
84
- 每个坏味道按*是什么* → *怎么修*来读;用它对照 diff:
85
-
86
- - **Mysterious Name** — 函数、变量或类型的名字没有揭示它做什么或装什么。→ 重命名;如果想不出诚实的名字,说明设计本身就是浑浊的。
87
- - **Duplicated Code** — 同样的逻辑形状出现在变更的多个 hunk 或文件中。→ 提取共同形状,两处都调用它。
88
- - **Feature Envy** — 一个方法伸进另一个对象的数据比用自己的还多。→ 把方法移到它羡慕的数据上。
89
- - **Data Clumps** — 同样几个字段或参数总是结伴出行(一个想诞生的类型)。→ 打包成一个类型,传那个类型。
90
- - **Primitive Obsession** — 用原始类型或字符串顶替一个本该有自己类型的领域概念。→ 给这个概念一个小类型。
91
- - **Repeated Switches** — 针对同一类型的同一个 `switch`/`if` 级联在变更中反复出现。→ 换成多态,或换成两处共享的一张 map。
92
- - **Shotgun Surgery** — 一个逻辑变更迫使 diff 中许多文件被零散修改。→ 把一起变的东西收进一个模块。
93
- - **Divergent Change** — 一个文件或模块因为多个不相关的原因被修改。→ 拆开,让每个模块只为一个原因变化。
94
- - **Speculative Generality** — 为 spec 并不存在的需求添加的抽象、参数或钩子。→ 删掉它;内联回去,等真实需求出现再说。
95
- - **Message Chains** — 调用方不该依赖的长 `a.b().c().d()` 导航链。→ 把这段行走藏到第一个对象上的一个方法背后。
96
- - **Middle Man** — 一个基本上只做转发的类或函数。→ 砍掉它,直接调用真正的目标。
97
- - **Refused Bequest** — 忽略或重写掉大部分继承物的子类或实现者。→ 放弃继承,改用组合。
41
+ - **永远是判断题。** 每个坏味道都是带标签的启发式("possible Feature Envy"),绝不是硬性违规;工具已经强制的事一律跳过。
42
+
43
+ 对照 diff 逐项检查:
44
+
45
+ - **Mysterious Name** — 函数、变量或类型的名字没有揭示它做什么或装什么。
46
+ - **Duplicated Code** — 同样的逻辑形状出现在变更的多个 hunk 或文件中。
47
+ - **Feature Envy** — 一个方法伸进另一个对象的数据比用自己的还多。
48
+ - **Data Clumps** — 同样几个字段或参数总是结伴出行(一个想诞生的类型)。
49
+ - **Primitive Obsession** — 用原始类型或字符串顶替一个本该有自己类型的领域概念。
50
+ - **Repeated Switches** — 针对同一类型的同一个 `switch`/`if` 级联在变更中反复出现。
51
+ - **Shotgun Surgery** — 一个逻辑变更迫使 diff 中许多文件被零散修改。
52
+ - **Divergent Change** — 一个文件或模块因为多个不相关的原因被修改。
53
+ - **Speculative Generality** — 为 spec 并不存在的需求添加的抽象、参数或钩子。
54
+ - **Message Chains** — 调用方不该依赖的长 `a.b().c().d()` 导航链。
55
+ - **Middle Man** — 一个基本上只做转发的类或函数。
56
+ - **Refused Bequest** — 忽略或重写掉大部分继承物的子类或实现者。
98
57
 
99
58
  ### 4. 并行启动两个 sub-agent
100
59
 
101
60
  **Standards sub-agent 的 prompt** — 包含:
102
61
 
103
62
  - 完整的 diff 命令和提交列表。
104
- - 第 3 步找到的规范来源文件列表,**外加第 3 步的坏味道基线**全文粘贴——sub-agent 没有其他途径获取它。
63
+ - 第 3 步找到的规范来源文件列表,**外加第 3 步的坏味道基线** 全文粘贴——sub-agent 没有其他途径获取它。
105
64
  - 简报:"汇报——在相关的文件/hunk 级别——(a) diff 违反文档化规范的每一处:引用该规范(文件 + 规则);(b) 你发现的所有基线坏味道:点名并引用该 hunk。区分硬性违规与判断题——文档化规范的违反可以是硬性违规,但基线坏味道永远是判断题,且文档化的 repo 规范优先于基线。工具已经强制的事一律跳过。400 词以内。"
106
65
 
107
66
  **Spec sub-agent 的 prompt** — 包含:
108
67
 
109
68
  - diff 命令和提交列表。
110
- - spec 的路径或抓取到的内容。
69
+ - spec 的路径或抓取到的内容,外加下面的检查清单(逐项对照):计划对齐(实现匹配需求、偏差合理、功能齐全);代码质量(关注点分离、错误处理、类型安全、DRY、边界情况);架构(设计合理、可扩展性与性能、安全、与周边集成);测试(验证真实行为而非 mock、边界与集成覆盖、全部通过);生产就绪(schema 迁移、向后兼容、文档、明显 bug)。
111
70
  - 简报:"汇报:(a) spec 要求但缺失或只完成了一部分的需求;(b) diff 中没人要求的行为(范围蔓延);(c) 看似已实现但实现看起来不对的需求。每条发现都要引用对应的 spec 原文行。400 词以内。"
112
71
 
113
72
  如果 spec 缺失,跳过 Spec sub-agent,并在最终报告中注明。
@@ -1,357 +0,0 @@
1
- ---
2
- name: playwright-cli
3
- description: 自动化浏览器交互、测试网页以及处理Playwright测试用例
4
- allowed-tools: Bash(playwright-cli:*) Bash(npx:*) Bash(npm:*)
5
- ---
6
-
7
- # playwright-cli 浏览器自动化工具
8
-
9
- > 🔴 ⚠️ 【强制规则,必须遵守】⚠️ 🔴
10
- > 🔴 所有调用`playwright-cli open`的命令,必须默认加上`--headed`参数!
11
- > 🔴 仅用户明确要求使用无头模式时,才可去掉该参数!
12
- > 🔴 禁止后台静默运行浏览器,必须显示窗口!
13
-
14
- ## 快速入门
15
-
16
- ```bash
17
- # 打开新浏览器
18
- playwright-cli open
19
- # 跳转到指定页面
20
- playwright-cli goto https://playwright.dev
21
- # 使用快照中的元素引用与页面交互
22
- playwright-cli click e15
23
- playwright-cli type "page.click"
24
- playwright-cli press Enter
25
- # 截图(较少使用,快照功能更常用)
26
- playwright-cli screenshot
27
- # 关闭浏览器
28
- playwright-cli close
29
- ```
30
-
31
- ## 命令说明
32
-
33
- ### 核心命令
34
-
35
- ```bash
36
- playwright-cli open
37
- # 打开浏览器并直接跳转到指定url
38
- playwright-cli open https://example.com/
39
- playwright-cli goto https://playwright.dev
40
- playwright-cli type "搜索关键词"
41
- playwright-cli click e3
42
- playwright-cli dblclick e7
43
- # --submit参数会在填充元素后自动按回车提交
44
- playwright-cli fill e5 "user@example.com" --submit
45
- playwright-cli drag e2 e8
46
- playwright-cli hover e4
47
- playwright-cli select e9 "选项值"
48
- playwright-cli upload ./document.pdf
49
- playwright-cli check e12
50
- playwright-cli uncheck e12
51
- playwright-cli snapshot
52
- playwright-cli eval "document.title"
53
- playwright-cli eval "el => el.textContent" e5
54
- # 获取快照中不显示的元素id、class或其他属性
55
- playwright-cli eval "el => el.id" e5
56
- playwright-cli eval "el => el.getAttribute('data-testid')" e5
57
- playwright-cli dialog-accept
58
- playwright-cli dialog-accept "确认文本"
59
- playwright-cli dialog-dismiss
60
- playwright-cli resize 1920 1080
61
- playwright-cli close
62
- ```
63
-
64
- ### 导航命令
65
-
66
- ```bash
67
- playwright-cli go-back
68
- playwright-cli go-forward
69
- playwright-cli reload
70
- ```
71
-
72
- ### 键盘命令
73
-
74
- ```bash
75
- playwright-cli press Enter
76
- playwright-cli press ArrowDown
77
- playwright-cli keydown Shift
78
- playwright-cli keyup Shift
79
- ```
80
-
81
- ### 鼠标命令
82
-
83
- ```bash
84
- playwright-cli mousemove 150 300
85
- playwright-cli mousedown
86
- playwright-cli mousedown right
87
- playwright-cli mouseup
88
- playwright-cli mouseup right
89
- playwright-cli mousewheel 0 100
90
- ```
91
-
92
- ### 导出命令
93
-
94
- ```bash
95
- playwright-cli screenshot
96
- playwright-cli screenshot e5
97
- playwright-cli screenshot --filename=page.png
98
- playwright-cli pdf --filename=page.pdf
99
- ```
100
-
101
- ### 标签页命令
102
-
103
- ```bash
104
- playwright-cli tab-list
105
- playwright-cli tab-new
106
- playwright-cli tab-new https://example.com/page
107
- playwright-cli tab-close
108
- playwright-cli tab-close 2
109
- playwright-cli tab-select 0
110
- ```
111
-
112
- ### 存储命令
113
-
114
- ```bash
115
- playwright-cli state-save
116
- playwright-cli state-save auth.json
117
- playwright-cli state-load auth.json
118
-
119
- # Cookie操作
120
- playwright-cli cookie-list
121
- playwright-cli cookie-list --domain=example.com
122
- playwright-cli cookie-get session_id
123
- playwright-cli cookie-set session_id abc123
124
- playwright-cli cookie-set session_id abc123 --domain=example.com --httpOnly --secure
125
- playwright-cli cookie-delete session_id
126
- playwright-cli cookie-clear
127
-
128
- # LocalStorage操作
129
- playwright-cli localstorage-list
130
- playwright-cli localstorage-get theme
131
- playwright-cli localstorage-set theme dark
132
- playwright-cli localstorage-delete theme
133
- playwright-cli localstorage-clear
134
-
135
- # SessionStorage操作
136
- playwright-cli sessionstorage-list
137
- playwright-cli sessionstorage-get step
138
- playwright-cli sessionstorage-set step 3
139
- playwright-cli sessionstorage-delete step
140
- playwright-cli sessionstorage-clear
141
- ```
142
-
143
- ### 网络命令
144
-
145
- ```bash
146
- playwright-cli route "**/*.jpg" --status=404
147
- playwright-cli route "https://api.example.com/**" --body='{"mock": true}'
148
- playwright-cli route-list
149
- playwright-cli unroute "**/*.jpg"
150
- playwright-cli unroute
151
- ```
152
-
153
- ### 开发者工具命令
154
-
155
- ```bash
156
- playwright-cli console
157
- playwright-cli console warning
158
- playwright-cli network
159
- playwright-cli run-code "async page => await page.context().grantPermissions(['geolocation'])"
160
- playwright-cli run-code --filename=script.js
161
- playwright-cli tracing-start
162
- playwright-cli tracing-stop
163
- playwright-cli video-start video.webm
164
- playwright-cli video-chapter "章节标题" --description="详细说明" --duration=2000
165
- playwright-cli video-stop
166
- ```
167
-
168
- ## 原始输出模式
169
-
170
- 全局参数`--raw`会去掉页面状态、生成代码和快照部分的输出,仅返回结果值,适合将命令输出管道到其他工具使用。没有输出的命令执行后不会返回任何内容。
171
-
172
- ```bash
173
- playwright-cli --raw eval "JSON.stringify(performance.timing)" | jq '.loadEventEnd - .navigationStart'
174
- playwright-cli --raw eval "JSON.stringify([...document.querySelectorAll('a')].map(a => a.href))" > links.json
175
- playwright-cli --raw snapshot > before.yml
176
- playwright-cli click e5
177
- playwright-cli --raw snapshot > after.yml
178
- diff before.yml after.yml
179
- TOKEN=$(playwright-cli --raw cookie-get session_id)
180
- playwright-cli --raw localstorage-get theme
181
- ```
182
-
183
- ## 启动参数
184
-
185
- ```bash
186
- # 启动时指定使用的浏览器,可选值:chrome, firefox, webkit, msedge
187
- playwright-cli open --browser=chrome
188
- playwright-cli open --browser=firefox
189
- playwright-cli open --browser=webkit
190
- playwright-cli open --browser=msedge
191
-
192
- # 使用持久化浏览器配置文件(默认使用内存中的临时配置,关闭后清空所有数据)
193
- playwright-cli open --persistent
194
- # 自定义持久化配置文件的存储目录
195
- playwright-cli open --profile=/path/to/profile
196
-
197
- # 通过扩展连接到浏览器
198
- playwright-cli attach --extension
199
-
200
- # 通过通道名连接到正在运行的Chrome或Edge
201
- playwright-cli attach --cdp=chrome
202
- playwright-cli attach --cdp=msedge
203
-
204
- # 通过CDP端点连接到正在运行的浏览器
205
- playwright-cli attach --cdp=http://localhost:9222
206
-
207
- # 从指定配置文件启动
208
- playwright-cli open --config=my-config.json
209
-
210
- # 关闭浏览器
211
- playwright-cli close
212
- # 删除默认会话的用户数据
213
- playwright-cli delete-data
214
- ```
215
-
216
- ## 快照功能
217
-
218
- 每次命令执行后,playwright-cli都会返回当前浏览器状态的快照。
219
-
220
- ```bash
221
- > playwright-cli goto https://example.com
222
- ### 页面信息
223
- - 页面URL: https://example.com/
224
- - 页面标题: Example Domain
225
- ### 快照
226
- [Snapshot](.playwright-cli/page-2026-02-14T19-22-42-679Z.yml)
227
- ```
228
-
229
- 你也可以按需手动执行`snapshot`命令获取快照,所有参数可以组合使用:
230
-
231
- ```bash
232
- # 默认保存到按时间戳命名的文件
233
- playwright-cli snapshot
234
-
235
- # 保存到指定文件,适合工作流结果中使用快照
236
- playwright-cli snapshot --filename=after-click.yaml
237
-
238
- # 仅快照指定元素而非整个页面
239
- playwright-cli snapshot "#main"
240
-
241
- # 限制快照的深度提升效率,之后可以对指定元素单独快照
242
- playwright-cli snapshot --depth=4
243
- playwright-cli snapshot e34
244
- ```
245
-
246
- ## 元素定位
247
-
248
- 默认使用快照中的元素引用(比如e15这种形式)来和页面元素交互。
249
-
250
- ```bash
251
- # 获取带元素引用的快照
252
- playwright-cli snapshot
253
-
254
- # 使用元素引用进行交互
255
- playwright-cli click e15
256
- ```
257
-
258
- 你也可以使用css选择器或者Playwright内置选择器:
259
-
260
- ```bash
261
- # css选择器
262
- playwright-cli click "#main > button.submit"
263
-
264
- # 角色选择器
265
- playwright-cli click "getByRole('button', { name: 'Submit' })"
266
-
267
- # 测试ID选择器
268
- playwright-cli click "getByTestId('submit-button')"
269
- ```
270
-
271
- ## 浏览器会话
272
-
273
- ```bash
274
- # 创建名为mysession的新浏览器会话,使用持久化配置
275
- playwright-cli -s=mysession open example.com --persistent
276
- # 手动指定配置文件目录(需要时使用)
277
- playwright-cli -s=mysession open example.com --profile=/path/to/profile
278
- playwright-cli -s=mysession click e6
279
- playwright-cli -s=mysession close # 停止指定名称的浏览器会话
280
- playwright-cli -s=mysession delete-data # 删除持久化会话的用户数据
281
-
282
- playwright-cli list
283
- # 关闭所有浏览器
284
- playwright-cli close-all
285
- # 强制终止所有浏览器进程
286
- playwright-cli kill-all
287
- ```
288
-
289
- ## 安装说明
290
-
291
- 如果全局`playwright-cli`命令不可用,可以尝试通过npx使用本地版本:
292
-
293
- ```bash
294
- npx --no-install playwright-cli --version
295
- ```
296
-
297
- 如果本地版本可用,所有命令都可以用`npx playwright-cli`代替。否则可以全局安装playwright-cli:
298
-
299
- ```bash
300
- npm install -g @playwright/cli@latest
301
- ```
302
-
303
- ## 示例:表单提交
304
-
305
- ```bash
306
- playwright-cli open https://example.com/form
307
- playwright-cli snapshot
308
-
309
- playwright-cli fill e1 "user@example.com"
310
- playwright-cli fill e2 "password123"
311
- playwright-cli click e3
312
- playwright-cli snapshot
313
- playwright-cli close
314
- ```
315
-
316
- ## 示例:多标签页工作流
317
-
318
- ```bash
319
- playwright-cli open https://example.com
320
- playwright-cli tab-new https://example.com/other
321
- playwright-cli tab-list
322
- playwright-cli tab-select 0
323
- playwright-cli snapshot
324
- playwright-cli close
325
- ```
326
-
327
- ## 示例:使用开发者工具调试
328
-
329
- ```bash
330
- playwright-cli open https://example.com
331
- playwright-cli click e4
332
- playwright-cli fill e7 "test"
333
- playwright-cli console
334
- playwright-cli network
335
- playwright-cli close
336
- ```
337
-
338
- ```bash
339
- playwright-cli open https://example.com
340
- playwright-cli tracing-start
341
- playwright-cli click e4
342
- playwright-cli fill e7 "test"
343
- playwright-cli tracing-stop
344
- playwright-cli close
345
- ```
346
-
347
- ## 特定场景用法
348
-
349
- * **运行和调试Playwright测试用例** [references/playwright-tests.md](references/playwright-tests.md)
350
- * **请求Mock** [references/request-mocking.md](references/request-mocking.md)
351
- * **运行Playwright代码** [references/running-code.md](references/running-code.md)
352
- * **浏览器会话管理** [references/session-management.md](references/session-management.md)
353
- * **存储状态(Cookie、localStorage)** [references/storage-state.md](references/storage-state.md)
354
- * **测试用例生成** [references/test-generation.md](references/test-generation.md)
355
- * **链路追踪** [references/tracing.md](references/tracing.md)
356
- * **视频录制** [references/video-recording.md](references/video-recording.md)
357
- * **元素属性检查** [references/element-attributes.md](references/element-attributes.md)
@@ -1,23 +0,0 @@
1
- # Inspecting Element Attributes
2
-
3
- When the snapshot doesn't show an element's `id`, `class`, `data-*` attributes, or other DOM properties, use `eval` to inspect them.
4
-
5
- ## Examples
6
-
7
- ```bash
8
- playwright-cli snapshot
9
- # snapshot shows a button as e7 but doesn't reveal its id or data attributes
10
-
11
- # get the element's id
12
- playwright-cli eval "el => el.id" e7
13
-
14
- # get all CSS classes
15
- playwright-cli eval "el => el.className" e7
16
-
17
- # get a specific attribute
18
- playwright-cli eval "el => el.getAttribute('data-testid')" e7
19
- playwright-cli eval "el => el.getAttribute('aria-label')" e7
20
-
21
- # get a computed style property
22
- playwright-cli eval "el => getComputedStyle(el).display" e7
23
- ```
@@ -1,39 +0,0 @@
1
- # Running Playwright Tests
2
-
3
- To run Playwright tests, use the `npx playwright test` command, or a package manager script. To avoid opening the interactive html report, use `PLAYWRIGHT_HTML_OPEN=never` environment variable.
4
-
5
- ```bash
6
- # Run all tests
7
- PLAYWRIGHT_HTML_OPEN=never npx playwright test
8
-
9
- # Run all tests through a custom npm script
10
- PLAYWRIGHT_HTML_OPEN=never npm run special-test-command
11
- ```
12
-
13
- # Debugging Playwright Tests
14
-
15
- To debug a failing Playwright test, run it with `--debug=cli` option. This command will pause the test at the start and print the debugging instructions.
16
-
17
- **IMPORTANT**: run the command in the background and check the output until "Debugging Instructions" is printed.
18
-
19
- Once instructions containing a session name are printed, use `playwright-cli` to attach the session and explore the page.
20
-
21
- ```bash
22
- # Run the test
23
- PLAYWRIGHT_HTML_OPEN=never npx playwright test --debug=cli
24
- # ...
25
- # ... debugging instructions for "tw-abcdef" session ...
26
- # ...
27
-
28
- # Attach to the test
29
- playwright-cli attach tw-abcdef
30
- ```
31
-
32
- Keep the test running in the background while you explore and look for a fix.
33
- The test is paused at the start, so you should step over or pause at a particular location
34
- where the problem is most likely to be.
35
-
36
- Every action you perform with `playwright-cli` generates corresponding Playwright TypeScript code.
37
- This code appears in the output and can be copied directly into the test. Most of the time, a specific locator or an expectation should be updated, but it could also be a bug in the app. Use your judgement.
38
-
39
- After fixing the test, stop the background test run. Rerun to check that test passes.
@@ -1,87 +0,0 @@
1
- # Request Mocking
2
-
3
- Intercept, mock, modify, and block network requests.
4
-
5
- ## CLI Route Commands
6
-
7
- ```bash
8
- # Mock with custom status
9
- playwright-cli route "**/*.jpg" --status=404
10
-
11
- # Mock with JSON body
12
- playwright-cli route "**/api/users" --body='[{"id":1,"name":"Alice"}]' --content-type=application/json
13
-
14
- # Mock with custom headers
15
- playwright-cli route "**/api/data" --body='{"ok":true}' --header="X-Custom: value"
16
-
17
- # Remove headers from requests
18
- playwright-cli route "**/*" --remove-header=cookie,authorization
19
-
20
- # List active routes
21
- playwright-cli route-list
22
-
23
- # Remove a route or all routes
24
- playwright-cli unroute "**/*.jpg"
25
- playwright-cli unroute
26
- ```
27
-
28
- ## URL Patterns
29
-
30
- ```
31
- **/api/users - Exact path match
32
- **/api/*/details - Wildcard in path
33
- **/*.{png,jpg,jpeg} - Match file extensions
34
- **/search?q=* - Match query parameters
35
- ```
36
-
37
- ## Advanced Mocking with run-code
38
-
39
- For conditional responses, request body inspection, response modification, or delays:
40
-
41
- ### Conditional Response Based on Request
42
-
43
- ```bash
44
- playwright-cli run-code "async page => {
45
- await page.route('**/api/login', route => {
46
- const body = route.request().postDataJSON();
47
- if (body.username === 'admin') {
48
- route.fulfill({ body: JSON.stringify({ token: 'mock-token' }) });
49
- } else {
50
- route.fulfill({ status: 401, body: JSON.stringify({ error: 'Invalid' }) });
51
- }
52
- });
53
- }"
54
- ```
55
-
56
- ### Modify Real Response
57
-
58
- ```bash
59
- playwright-cli run-code "async page => {
60
- await page.route('**/api/user', async route => {
61
- const response = await route.fetch();
62
- const json = await response.json();
63
- json.isPremium = true;
64
- await route.fulfill({ response, json });
65
- });
66
- }"
67
- ```
68
-
69
- ### Simulate Network Failures
70
-
71
- ```bash
72
- playwright-cli run-code "async page => {
73
- await page.route('**/api/offline', route => route.abort('internetdisconnected'));
74
- }"
75
- # Options: connectionrefused, timedout, connectionreset, internetdisconnected
76
- ```
77
-
78
- ### Delayed Response
79
-
80
- ```bash
81
- playwright-cli run-code "async page => {
82
- await page.route('**/api/slow', async route => {
83
- await new Promise(r => setTimeout(r, 3000));
84
- route.fulfill({ body: JSON.stringify({ data: 'loaded' }) });
85
- });
86
- }"
87
- ```