@szc-ft/mcp-szcd-client 0.18.0 → 0.19.0
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/agents/qwen-extension/agents/szcd-component-expert.md +22 -0
- package/agents/src/szcd-component-expert.md +32 -2
- package/agents/szcd-component-expert.md +22 -0
- package/agents/szcd-component-expert.qoder.md +29 -2
- package/agents/szcd-component-expert.trae.md +29 -2
- package/commands/szcd-mcp-browser-test.md +57 -0
- package/commands/szcd-mcp-feedback.md +42 -0
- package/lib/browser-engine.js +379 -0
- package/lib/chrome-finder.js +125 -0
- package/lib/visual-compare.js +189 -0
- package/local-browser-executor.js +239 -0
- package/package.json +9 -1
- package/qwen-extension/agents/szcd-component-expert.md +22 -0
- package/qwen-extension/commands/szcd-mcp-browser-test.md +57 -0
- package/qwen-extension/commands/szcd-mcp-feedback.md +42 -0
- package/qwen-extension/qwen-extension.json +1 -1
- package/qwen-extension/skills/local-api-tool/SKILL.md +14 -1
- package/qwen-extension/skills/local-browser-test/SKILL.md +153 -0
- package/standard-skill/local-api-tool/SKILL.md +14 -1
- package/standard-skill/local-browser-test/SKILL.md +153 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: local-browser-test
|
|
3
|
+
description: 本地浏览器测试工具,在用户本地 Chrome 中执行自动化测试。支持设计稿还原度对比(像素级评分)、功能验证(点击/输入/导航)、DOM 结构检查、JS 错误检测。通过 puppeteer-core 连接用户真实浏览器,天然继承登录态和微前端环境。
|
|
4
|
+
compatibility:
|
|
5
|
+
tools:
|
|
6
|
+
- run_command
|
|
7
|
+
- read_file
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# 本地浏览器测试工具(local-browser-test)
|
|
11
|
+
|
|
12
|
+
## 触发条件
|
|
13
|
+
|
|
14
|
+
当用户说出以下关键词时启动浏览器测试:
|
|
15
|
+
- "测试一下"、"帮我验证"、"浏览器测试"
|
|
16
|
+
- "对比设计稿"、"还原度"、"看看效果"
|
|
17
|
+
- "功能测试"、"能不能正常用"
|
|
18
|
+
- "检查页面"、"页面渲染"
|
|
19
|
+
|
|
20
|
+
## 浏览器模式
|
|
21
|
+
|
|
22
|
+
支持两种模式,执行器自动检测优先使用 connect:
|
|
23
|
+
|
|
24
|
+
### connect 模式(推荐)
|
|
25
|
+
连接用户已启动的调试 Chrome,天然继承登录态/微前端环境。
|
|
26
|
+
|
|
27
|
+
用户一次性配置:
|
|
28
|
+
```bash
|
|
29
|
+
# macOS
|
|
30
|
+
open -a "Google Chrome" --args --remote-debugging-port=9222
|
|
31
|
+
# Linux
|
|
32
|
+
google-chrome --remote-debugging-port=9222
|
|
33
|
+
# Windows
|
|
34
|
+
"C:\Program Files\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9222
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### launch 模式(回退)
|
|
38
|
+
启动新的 headless Chrome,需要用户提供可直接访问的 URL。
|
|
39
|
+
|
|
40
|
+
执行器会自动检测 localhost:9222 是否可用,有则 connect,无则 launch。
|
|
41
|
+
|
|
42
|
+
## 测试计划 Schema
|
|
43
|
+
|
|
44
|
+
AI 直接构造测试计划 JSON:
|
|
45
|
+
|
|
46
|
+
```json
|
|
47
|
+
{
|
|
48
|
+
"planId": "<uuid>",
|
|
49
|
+
"description": "<测试描述>",
|
|
50
|
+
"steps": [ ... ],
|
|
51
|
+
"options": {
|
|
52
|
+
"viewport": { "width": 1440, "height": 900 },
|
|
53
|
+
"timeout": 120000,
|
|
54
|
+
"outputDir": "/tmp/browser-test-<planId>"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### 支持的步骤类型
|
|
60
|
+
|
|
61
|
+
| type | 功能 | 参数 | 返回 |
|
|
62
|
+
|------|------|------|------|
|
|
63
|
+
| navigate | 导航到 URL | `url`, `waitUntil` | `{ url, title, loadTime }` |
|
|
64
|
+
| screenshot | 页面截图 | `fullPage`, `clip`, `filename` | `{ filepath, width, height }` |
|
|
65
|
+
| compare | 设计稿对比 | `designImagePath`, `threshold`, `regions[]` | `{ fidelity, diffPixels, diffImagePath, regions[] }` |
|
|
66
|
+
| click | 点击元素 | `selector`, `waitForNavigation` | `{ clicked, tagName }` |
|
|
67
|
+
| type | 输入文本 | `selector`, `text`, `clear` | `{ typed, value }` |
|
|
68
|
+
| waitFor | 等待条件 | `selector` 或 `url`, `timeout` | `{ matched, waited }` |
|
|
69
|
+
| evaluate | 执行 JS | `expression` | `{ result }` |
|
|
70
|
+
| checkElement | 元素断言 | `selector`, `expect: {visible, minCount, maxCount, hasText}` | `{ passed, checks, elementCount }` |
|
|
71
|
+
|
|
72
|
+
### 场景选择策略
|
|
73
|
+
|
|
74
|
+
根据上下文自动选择步骤组合:
|
|
75
|
+
|
|
76
|
+
**场景 A:有设计稿 + 功能验证(最完整)**
|
|
77
|
+
`navigate → waitFor → screenshot → compare → 功能步骤`
|
|
78
|
+
|
|
79
|
+
**场景 B:无设计稿 + 功能验证**
|
|
80
|
+
`navigate → waitFor → screenshot → evaluate(JS错误检查) → 功能步骤`
|
|
81
|
+
|
|
82
|
+
**场景 C:仅视觉对比**
|
|
83
|
+
`navigate → waitFor → screenshot → compare`
|
|
84
|
+
|
|
85
|
+
**场景 D:仅页面检查**
|
|
86
|
+
`navigate → waitFor → screenshot → evaluate(JS错误检查)`
|
|
87
|
+
|
|
88
|
+
### 构造步骤的指导原则
|
|
89
|
+
|
|
90
|
+
1. **selector 必须从用户代码中读取,不要猜测**
|
|
91
|
+
- 读代码中的 `id`、`className`、`data-testid`
|
|
92
|
+
- szcd 组件的 class 可通过 `get_component_full_profile` 获取
|
|
93
|
+
2. **API 路径从代码中的接口调用读取**
|
|
94
|
+
3. **checkElement 的 expect 从代码逻辑推断**
|
|
95
|
+
- columns 定义了 N 列 → `expect: { minCount: N }`(检查 th 数量)
|
|
96
|
+
- dataSource 有数据 → `expect: { minCount: 1 }`(检查行数)
|
|
97
|
+
4. **compare 的 regions 从设计稿分析结果或组件布局推断**
|
|
98
|
+
|
|
99
|
+
## 执行命令
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
node {client_install_path}/local-browser-executor.js \
|
|
103
|
+
--plan '<测试计划JSON>' \
|
|
104
|
+
--output /tmp/browser-test-result.json
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
也支持从文件读取计划:
|
|
108
|
+
```bash
|
|
109
|
+
node {client_install_path}/local-browser-executor.js \
|
|
110
|
+
--plan-file /tmp/test-plan.json \
|
|
111
|
+
--output /tmp/browser-test-result.json
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### 可选参数
|
|
115
|
+
|
|
116
|
+
- `--cdp-url http://localhost:9223`:指定非默认的 CDP 端口
|
|
117
|
+
- `--page-url http://xxx/page`:connect 模式下指定目标页面
|
|
118
|
+
|
|
119
|
+
## 依赖检查
|
|
120
|
+
|
|
121
|
+
如果执行报错依赖缺失,引导用户安装:
|
|
122
|
+
```bash
|
|
123
|
+
npm install puppeteer-core pixelmatch pngjs sharp
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## 结果解读
|
|
127
|
+
|
|
128
|
+
### 还原度评分
|
|
129
|
+
- fidelity >= 95%:还原度优秀
|
|
130
|
+
- fidelity 90-95%:还原度良好,有优化空间
|
|
131
|
+
- fidelity < 90%:还原度不足,需要调整
|
|
132
|
+
|
|
133
|
+
### 功能测试
|
|
134
|
+
- passed = total:全部通过
|
|
135
|
+
- 有失败步骤:根据 `step` + `error` 字段定位代码问题
|
|
136
|
+
|
|
137
|
+
### 结果文件结构
|
|
138
|
+
```json
|
|
139
|
+
{
|
|
140
|
+
"planId": "xxx",
|
|
141
|
+
"mode": "connect",
|
|
142
|
+
"steps": [
|
|
143
|
+
{ "index": 1, "step": "navigate", "status": "PASS", "duration": 1200, ... },
|
|
144
|
+
{ "index": 2, "step": "screenshot", "status": "PASS", "duration": 500, ... },
|
|
145
|
+
{ "index": 3, "step": "compare", "status": "PASS", "fidelity": 94.7, ... }
|
|
146
|
+
],
|
|
147
|
+
"summary": {
|
|
148
|
+
"total": 5, "passed": 4, "failed": 1,
|
|
149
|
+
"fidelity": 94.7
|
|
150
|
+
},
|
|
151
|
+
"outputDir": "/tmp/browser-test-xxx"
|
|
152
|
+
}
|
|
153
|
+
```
|