@szc-ft/mcp-szcd-client 0.27.4 → 0.28.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/lib/ant-adapter.js +716 -0
- package/lib/browser-engine.js +471 -0
- package/lib/expect.js +392 -0
- package/lib/test-plan.js +48 -0
- package/local-browser-executor.js +70 -1
- package/opencode-extension/skills/local-browser-test/SKILL.md +113 -0
- package/package.json +1 -1
- package/qwen-extension/qwen-extension.json +1 -1
- package/qwen-extension/skills/local-browser-test/SKILL.md +113 -0
- package/standard-skill/local-browser-test/SKILL.md +113 -0
|
@@ -547,6 +547,119 @@ cd ~/.szcd-mcp/deps && npm install --registry=https://registry.npmmirror.com --@
|
|
|
547
547
|
| `setTimeout(awaitPage.bringToFront(), 30000)` 之外不做兜底 | 调用前自查"目标页是否还活着"(`findPage` / `_findFrame`),失败立刻退而求其次操作主帧 | bringToFront 在 OS 抢焦点失败时会无限挂起,没超时 |
|
|
548
548
|
| iframe attach 失败就报错退出 | `attachRetries` 默认 3 次、间隔 1.5s 重抓 `browser.targets()` | wujie 的 blob iframe target 在主页面 ready 后才注册,时序敏感 |
|
|
549
549
|
| 大批量探索每条都 throw | `_actMenuPath` 失败时返回 `acted:false + candidates`,配合 `runTask --continue-on-fail` | 探索性扫描遇到一条点不开就全部中断,没法发现整体面 |
|
|
550
|
+
| 手写 puppeteer 脚本绕过 `act` 操作 Ant Select | 用 `antSelect` 步骤(内置 mousedown + 轮询 + closeAllDropdowns + VERIFY) | Ant Design Select 必须 mousedown 触发,浮层在 body 末尾,选项异步渲染,单步 `act.evaluate` 无法覆盖四步组合 |
|
|
551
|
+
| 每个 Select 后忘记 `closeAllDropdowns` | `act` 自动检测上一次 antSelect/antTreeSelect 并预清理 | 下拉浮层残留会污染下一次 Select 操作,选项串选 |
|
|
552
|
+
| 硬编码 `sleep(15*200)` 等选项渲染 | `antSelect` 内置 `pollEval` 15×200ms 轮询,`expect(poll)` 可自定义条件 | 选项渲染时间受网络/数据量影响,固定 sleep 时机不可靠 |
|
|
553
|
+
| 表单校验用 ad-hoc evaluate 检查 | 用 `expect validation.toPass` 或 `formFill` 的 `validateAfter` | 语义断言自带 poll + 结构化错误信息(field + message),可直接进报告 |
|
|
554
|
+
|
|
555
|
+
## Ant Design 适配层(6/22 反馈落地)
|
|
556
|
+
|
|
557
|
+
把"触发器定位 → 浮层等待 → 选项交互 → VERIFY → 全局清理"固化为单步骤 JSON。
|
|
558
|
+
|
|
559
|
+
| type | 功能 | 关键参数 |
|
|
560
|
+
|------|------|---------|
|
|
561
|
+
| `antSelect` | Ant Select 选项选择 | `field`, `option`, `mode` |
|
|
562
|
+
| `antTreeSelect` | 树形选择 | `field`, `path` |
|
|
563
|
+
| `antInput` | 输入框(支持 `placeholder` 定位) | `field`/`placeholder`, `value` |
|
|
564
|
+
| `antRadio` / `antCheckbox` / `antSwitch` | 选择类 | `field`, `option`/`on` |
|
|
565
|
+
| `antDatePicker` / `antCascader` / `antUpload` | 其他控件 | 见各方法文档 |
|
|
566
|
+
| `formFill` | 批量填充 + 可选 `validateAfter` | `fields[]` |
|
|
567
|
+
| `closeAllDropdowns` | 关闭所有下拉浮层 | - |
|
|
568
|
+
|
|
569
|
+
**关键约束**:
|
|
570
|
+
- Ant Select 必须 `mousedown` 触发(不是 click)
|
|
571
|
+
- 选项异步渲染,内置 15×200ms 轮询
|
|
572
|
+
- 每次操作前后自动 `closeAllDropdowns`,`act` 入口检测残留并预清理
|
|
573
|
+
- 操作后 VERIFY `.ant-select-selection-item[title]` 回写
|
|
574
|
+
|
|
575
|
+
```json
|
|
576
|
+
{ "type": "antSelect", "field": "数据集名称", "option": "测试集A" }
|
|
577
|
+
{ "type": "antInput", "placeholder": "挂接资源", "value": "abc" }
|
|
578
|
+
{ "type": "formFill", "fields": [
|
|
579
|
+
{ "label": "名称", "type": "input", "value": "{{name}}" },
|
|
580
|
+
{ "label": "类型", "type": "select", "value": "{{type}}" }
|
|
581
|
+
], "validateAfter": true }
|
|
582
|
+
```
|
|
583
|
+
|
|
584
|
+
## 用例 DSL(Test Case)
|
|
585
|
+
|
|
586
|
+
把多个用例统一为参数化 testCase JSON:
|
|
587
|
+
|
|
588
|
+
```bash
|
|
589
|
+
node local-browser-executor.js --action test-case --test-case-file /tmp/case.json [--dataset-index 0] [--test-report /tmp/report.json]
|
|
590
|
+
```
|
|
591
|
+
|
|
592
|
+
```json
|
|
593
|
+
{
|
|
594
|
+
"title": "创建数据集 - P0",
|
|
595
|
+
"dataset": [{ "name": "A", "type": "图像" }, { "name": "B", "type": "文本" }],
|
|
596
|
+
"steps": [
|
|
597
|
+
{ "type": "formFill", "fields": [
|
|
598
|
+
{ "label": "名称", "type": "input", "value": "{{name}}" },
|
|
599
|
+
{ "label": "类型", "type": "select", "value": "{{type}}" }
|
|
600
|
+
], "validateAfter": true },
|
|
601
|
+
{ "type": "expect", "assertion": "validation.toPass" },
|
|
602
|
+
{ "type": "act", "click": "text=提交" },
|
|
603
|
+
{ "type": "expect", "assertion": "url.toContain", "value": "/list" }
|
|
604
|
+
],
|
|
605
|
+
"recovery": { "maxRetriesPerStep": 2 }
|
|
606
|
+
}
|
|
607
|
+
```
|
|
608
|
+
|
|
609
|
+
## 语义断言(expect)
|
|
610
|
+
|
|
611
|
+
| assertion | 功能 |
|
|
612
|
+
|-----------|------|
|
|
613
|
+
| `validation.toPass` | 表单校验无错误 |
|
|
614
|
+
| `validation.toHaveError` | 某字段有错误 |
|
|
615
|
+
| `locator.toBeVisible` / `toHaveText` / `toHaveValue` / `toHaveCount` | 元素状态 |
|
|
616
|
+
| `url.toContain` / `url.toMatch` | URL 断言 |
|
|
617
|
+
| `api.toAllPass` / `api.toInclude` | API 断言 |
|
|
618
|
+
|
|
619
|
+
所有断言内置 `poll` 轮询(默认 timeout 5s, interval 200ms)。
|
|
620
|
+
|
|
621
|
+
## 微前端(wujie / qiankun)场景适配
|
|
622
|
+
|
|
623
|
+
**核心问题与解决:**
|
|
624
|
+
|
|
625
|
+
| 微前端坑 | 自动修复 |
|
|
626
|
+
|---------|---------|
|
|
627
|
+
| 子应用业务在 frame[1],每步都要重传 frameContentContains | testCase `setup.findFrame` 设一次,所有步骤默认走 `_activeFrame` |
|
|
628
|
+
| 子应用路由切换销毁 iframe,导致后续 step 都 evaluate 失败 | `_getTargetFrame` 每次执行前探活,失活自动召回(标记 `frameRecovered: true`) |
|
|
629
|
+
| Ant Select 的 `getPopupContainer` 把浮层渲染到父文档 | `antSelect` 触发器/浮层双 frame 协作:trigger 在子 frame mousedown,浮层在父 frame 找选项 |
|
|
630
|
+
| 残留浮层污染下一次操作 | `closeAllDropdowns` 跨 frame 清理(主 + 所有可访问子 frame) |
|
|
631
|
+
| `api.toAllPass` 因主应用埋点 404 误判子应用 P0 测试失败 | `step.scope: "current-frame"` 仅断言 `_activeFrame` 同源的请求 |
|
|
632
|
+
|
|
633
|
+
**testCase 微前端模板:**
|
|
634
|
+
|
|
635
|
+
```json
|
|
636
|
+
{
|
|
637
|
+
"title": "数据集创建 P0",
|
|
638
|
+
"setup": {
|
|
639
|
+
"findFrame": { "contentContains": "数据集目录" }
|
|
640
|
+
},
|
|
641
|
+
"dataset": [{ "name": "A" }, { "name": "B" }],
|
|
642
|
+
"steps": [
|
|
643
|
+
{ "type": "apiCapture", "urlPattern": "/api/dataset", "wait": 5000, "includeAllTargets": true },
|
|
644
|
+
{ "type": "antInput", "field": "名称", "value": "{{name}}" },
|
|
645
|
+
{ "type": "antSelect", "field": "类型", "option": "图像" },
|
|
646
|
+
{ "type": "act", "click": "text=提交" },
|
|
647
|
+
{ "type": "expect", "assertion": "validation.toPass" },
|
|
648
|
+
{ "type": "expect", "assertion": "api.toAllPass", "scope": "current-frame" }
|
|
649
|
+
]
|
|
650
|
+
}
|
|
651
|
+
```
|
|
652
|
+
|
|
653
|
+
**关键参数:**
|
|
654
|
+
|
|
655
|
+
- `setup.findFrame.contentContains` — 一次定位子应用 frame
|
|
656
|
+
- `step.frameContentContains` — 单步覆盖(少用,违反 DRY)
|
|
657
|
+
- `step.scope: "current-frame"` — API 断言仅看 `_activeFrame` 同源请求
|
|
658
|
+
- `apiCapture.includeAllTargets: true` — 跨 page/iframe target 监听网络
|
|
659
|
+
|
|
660
|
+
**调试技巧:**
|
|
661
|
+
|
|
662
|
+
每个 ant 步骤结果含 `triggerFrameUrl` / `popupFrameUrl`,可看到触发器和浮层实际在哪个 frame。若 `_dropdownFrame: "main"` 出现,说明该控件用了 `getPopupContainer` 跨 frame 渲染浮层。
|
|
550
663
|
|
|
551
664
|
## 非目标声明
|
|
552
665
|
|
|
@@ -547,6 +547,119 @@ cd ~/.szcd-mcp/deps && npm install --registry=https://registry.npmmirror.com --@
|
|
|
547
547
|
| `setTimeout(awaitPage.bringToFront(), 30000)` 之外不做兜底 | 调用前自查"目标页是否还活着"(`findPage` / `_findFrame`),失败立刻退而求其次操作主帧 | bringToFront 在 OS 抢焦点失败时会无限挂起,没超时 |
|
|
548
548
|
| iframe attach 失败就报错退出 | `attachRetries` 默认 3 次、间隔 1.5s 重抓 `browser.targets()` | wujie 的 blob iframe target 在主页面 ready 后才注册,时序敏感 |
|
|
549
549
|
| 大批量探索每条都 throw | `_actMenuPath` 失败时返回 `acted:false + candidates`,配合 `runTask --continue-on-fail` | 探索性扫描遇到一条点不开就全部中断,没法发现整体面 |
|
|
550
|
+
| 手写 puppeteer 脚本绕过 `act` 操作 Ant Select | 用 `antSelect` 步骤(内置 mousedown + 轮询 + closeAllDropdowns + VERIFY) | Ant Design Select 必须 mousedown 触发,浮层在 body 末尾,选项异步渲染,单步 `act.evaluate` 无法覆盖四步组合 |
|
|
551
|
+
| 每个 Select 后忘记 `closeAllDropdowns` | `act` 自动检测上一次 antSelect/antTreeSelect 并预清理 | 下拉浮层残留会污染下一次 Select 操作,选项串选 |
|
|
552
|
+
| 硬编码 `sleep(15*200)` 等选项渲染 | `antSelect` 内置 `pollEval` 15×200ms 轮询,`expect(poll)` 可自定义条件 | 选项渲染时间受网络/数据量影响,固定 sleep 时机不可靠 |
|
|
553
|
+
| 表单校验用 ad-hoc evaluate 检查 | 用 `expect validation.toPass` 或 `formFill` 的 `validateAfter` | 语义断言自带 poll + 结构化错误信息(field + message),可直接进报告 |
|
|
554
|
+
|
|
555
|
+
## Ant Design 适配层(6/22 反馈落地)
|
|
556
|
+
|
|
557
|
+
把"触发器定位 → 浮层等待 → 选项交互 → VERIFY → 全局清理"固化为单步骤 JSON。
|
|
558
|
+
|
|
559
|
+
| type | 功能 | 关键参数 |
|
|
560
|
+
|------|------|---------|
|
|
561
|
+
| `antSelect` | Ant Select 选项选择 | `field`, `option`, `mode` |
|
|
562
|
+
| `antTreeSelect` | 树形选择 | `field`, `path` |
|
|
563
|
+
| `antInput` | 输入框(支持 `placeholder` 定位) | `field`/`placeholder`, `value` |
|
|
564
|
+
| `antRadio` / `antCheckbox` / `antSwitch` | 选择类 | `field`, `option`/`on` |
|
|
565
|
+
| `antDatePicker` / `antCascader` / `antUpload` | 其他控件 | 见各方法文档 |
|
|
566
|
+
| `formFill` | 批量填充 + 可选 `validateAfter` | `fields[]` |
|
|
567
|
+
| `closeAllDropdowns` | 关闭所有下拉浮层 | - |
|
|
568
|
+
|
|
569
|
+
**关键约束**:
|
|
570
|
+
- Ant Select 必须 `mousedown` 触发(不是 click)
|
|
571
|
+
- 选项异步渲染,内置 15×200ms 轮询
|
|
572
|
+
- 每次操作前后自动 `closeAllDropdowns`,`act` 入口检测残留并预清理
|
|
573
|
+
- 操作后 VERIFY `.ant-select-selection-item[title]` 回写
|
|
574
|
+
|
|
575
|
+
```json
|
|
576
|
+
{ "type": "antSelect", "field": "数据集名称", "option": "测试集A" }
|
|
577
|
+
{ "type": "antInput", "placeholder": "挂接资源", "value": "abc" }
|
|
578
|
+
{ "type": "formFill", "fields": [
|
|
579
|
+
{ "label": "名称", "type": "input", "value": "{{name}}" },
|
|
580
|
+
{ "label": "类型", "type": "select", "value": "{{type}}" }
|
|
581
|
+
], "validateAfter": true }
|
|
582
|
+
```
|
|
583
|
+
|
|
584
|
+
## 用例 DSL(Test Case)
|
|
585
|
+
|
|
586
|
+
把多个用例统一为参数化 testCase JSON:
|
|
587
|
+
|
|
588
|
+
```bash
|
|
589
|
+
node local-browser-executor.js --action test-case --test-case-file /tmp/case.json [--dataset-index 0] [--test-report /tmp/report.json]
|
|
590
|
+
```
|
|
591
|
+
|
|
592
|
+
```json
|
|
593
|
+
{
|
|
594
|
+
"title": "创建数据集 - P0",
|
|
595
|
+
"dataset": [{ "name": "A", "type": "图像" }, { "name": "B", "type": "文本" }],
|
|
596
|
+
"steps": [
|
|
597
|
+
{ "type": "formFill", "fields": [
|
|
598
|
+
{ "label": "名称", "type": "input", "value": "{{name}}" },
|
|
599
|
+
{ "label": "类型", "type": "select", "value": "{{type}}" }
|
|
600
|
+
], "validateAfter": true },
|
|
601
|
+
{ "type": "expect", "assertion": "validation.toPass" },
|
|
602
|
+
{ "type": "act", "click": "text=提交" },
|
|
603
|
+
{ "type": "expect", "assertion": "url.toContain", "value": "/list" }
|
|
604
|
+
],
|
|
605
|
+
"recovery": { "maxRetriesPerStep": 2 }
|
|
606
|
+
}
|
|
607
|
+
```
|
|
608
|
+
|
|
609
|
+
## 语义断言(expect)
|
|
610
|
+
|
|
611
|
+
| assertion | 功能 |
|
|
612
|
+
|-----------|------|
|
|
613
|
+
| `validation.toPass` | 表单校验无错误 |
|
|
614
|
+
| `validation.toHaveError` | 某字段有错误 |
|
|
615
|
+
| `locator.toBeVisible` / `toHaveText` / `toHaveValue` / `toHaveCount` | 元素状态 |
|
|
616
|
+
| `url.toContain` / `url.toMatch` | URL 断言 |
|
|
617
|
+
| `api.toAllPass` / `api.toInclude` | API 断言 |
|
|
618
|
+
|
|
619
|
+
所有断言内置 `poll` 轮询(默认 timeout 5s, interval 200ms)。
|
|
620
|
+
|
|
621
|
+
## 微前端(wujie / qiankun)场景适配
|
|
622
|
+
|
|
623
|
+
**核心问题与解决:**
|
|
624
|
+
|
|
625
|
+
| 微前端坑 | 自动修复 |
|
|
626
|
+
|---------|---------|
|
|
627
|
+
| 子应用业务在 frame[1],每步都要重传 frameContentContains | testCase `setup.findFrame` 设一次,所有步骤默认走 `_activeFrame` |
|
|
628
|
+
| 子应用路由切换销毁 iframe,导致后续 step 都 evaluate 失败 | `_getTargetFrame` 每次执行前探活,失活自动召回(标记 `frameRecovered: true`) |
|
|
629
|
+
| Ant Select 的 `getPopupContainer` 把浮层渲染到父文档 | `antSelect` 触发器/浮层双 frame 协作:trigger 在子 frame mousedown,浮层在父 frame 找选项 |
|
|
630
|
+
| 残留浮层污染下一次操作 | `closeAllDropdowns` 跨 frame 清理(主 + 所有可访问子 frame) |
|
|
631
|
+
| `api.toAllPass` 因主应用埋点 404 误判子应用 P0 测试失败 | `step.scope: "current-frame"` 仅断言 `_activeFrame` 同源的请求 |
|
|
632
|
+
|
|
633
|
+
**testCase 微前端模板:**
|
|
634
|
+
|
|
635
|
+
```json
|
|
636
|
+
{
|
|
637
|
+
"title": "数据集创建 P0",
|
|
638
|
+
"setup": {
|
|
639
|
+
"findFrame": { "contentContains": "数据集目录" }
|
|
640
|
+
},
|
|
641
|
+
"dataset": [{ "name": "A" }, { "name": "B" }],
|
|
642
|
+
"steps": [
|
|
643
|
+
{ "type": "apiCapture", "urlPattern": "/api/dataset", "wait": 5000, "includeAllTargets": true },
|
|
644
|
+
{ "type": "antInput", "field": "名称", "value": "{{name}}" },
|
|
645
|
+
{ "type": "antSelect", "field": "类型", "option": "图像" },
|
|
646
|
+
{ "type": "act", "click": "text=提交" },
|
|
647
|
+
{ "type": "expect", "assertion": "validation.toPass" },
|
|
648
|
+
{ "type": "expect", "assertion": "api.toAllPass", "scope": "current-frame" }
|
|
649
|
+
]
|
|
650
|
+
}
|
|
651
|
+
```
|
|
652
|
+
|
|
653
|
+
**关键参数:**
|
|
654
|
+
|
|
655
|
+
- `setup.findFrame.contentContains` — 一次定位子应用 frame
|
|
656
|
+
- `step.frameContentContains` — 单步覆盖(少用,违反 DRY)
|
|
657
|
+
- `step.scope: "current-frame"` — API 断言仅看 `_activeFrame` 同源请求
|
|
658
|
+
- `apiCapture.includeAllTargets: true` — 跨 page/iframe target 监听网络
|
|
659
|
+
|
|
660
|
+
**调试技巧:**
|
|
661
|
+
|
|
662
|
+
每个 ant 步骤结果含 `triggerFrameUrl` / `popupFrameUrl`,可看到触发器和浮层实际在哪个 frame。若 `_dropdownFrame: "main"` 出现,说明该控件用了 `getPopupContainer` 跨 frame 渲染浮层。
|
|
550
663
|
|
|
551
664
|
## 非目标声明
|
|
552
665
|
|