feat(test): 文档化 dacli test render 源码渲染验证 (替代浏览器验证)
用户拍板: 把 06-27 Batch 1 字典验证的'读 vue + 调 API'方法
固化到 dacli test render 子命令, 替代浏览器验证.
新增子命令 (2026-06-27):
dacli test render --module=dict [--typeId=X] [--id=Y]
算法 (镜像 web 端渲染契约, 替代浏览器验证):
- @vue/compiler-sfc 解析 web/.../sysData/dictionary/*.vue
- list mode: 提取 BasicColumn[].dataIndex
- form mode: 提取 useForm({schemas:[{field}]}).field
- 调对应 API (DictionaryType / DictionaryData/{typeId})
- 对比: 渲染字段 ⊆ API 字段 ? PASS : FAIL
- 4 个页面覆盖: 类型列表 / 类型编辑 / 数据列表 / 数据编辑
vs 浏览器测试:
- 速度 2s vs 30s+
- 不需 playwright / 浏览器启动
- 不依赖 SPA 路由 (JNPF admin 菜单经常 404)
- 局限: 查不出 vmodel bind bug (浏览器 JS) → 仍需 ssw-e2e-test
源码镜像 (web 端):
- web/.../sysData/dictionary/index.vue L27-32 BasicColumn
- web/.../sysData/dictionary/Form.vue L19-62 useForm.schemas
- web/.../sysData/dictionary/components/index.vue L20-25 BasicColumn
- web/.../sysData/dictionary/components/Form.vue L19-69 useForm.schemas
- web/.../api/systemData/dictionary.ts L9-60 (4 API)
源码镜像 (JNPF 后端):
- jnpf/.../controller/DictionaryTypeController.java L57 L168-169
- jnpf/.../controller/DictionaryDataController.java L89 L257-258
阶段 5 测试 (v0.11+ 推荐):
- API 层: dacli test run (~5s)
- 源码渲染层: dacli test render (~2s) ★ 新
- Schema 层: webapi 镜像自动保证
- 浏览器层: ssw-e2e-test (visual regression)
Co-Authored-By: Claude <[email protected]>
This commit is contained in:
1 parent
a75799dd04
commit
ab5502aa46
2 files changed
+160
-4
No files matched your search
@@ -354,20 +354,44 @@ dacli dict typeCreate --fullName="TestDup2" --enCode="tdd10duptestv1" --parentId
|
||||
| `dacli user list --keyword=...` | 用户列表 (P1 权限三角 2 号) | `7224156` |
|
||||
| `dacli user create` / `dacli user delete <id>` | 建 / 删用户 | `7224156` |
|
||||
|
||||
### test (2 子, v0.11+ NEW, 沉淀 API 模拟录入; v0.11+ cleanup 删 `check`)
|
||||
### test (3 子, v0.11+ NEW, 沉淀 API 模拟录入 + 源码渲染验证; v0.11+ cleanup 删 `check`)
|
||||
| 命令 | 用途 | commit |
|
||||
|------|------|--------|
|
||||
| `dacli test run --formId=X` | **沉淀自 tdd10**: 跑 form API 测试 (POST/GET/PUT/DELETE 全流程, ~5s). 输出 markdown 报告 | `516f396` |
|
||||
| `dacli test gen --formId=X` | P1 stub: 从 form schema 生成可重用 shell/python 脚本 | `516f396` |
|
||||
| `dacli test render --module=dict [--typeId=X] [--id=Y]` | **★ 替代浏览器验证 (2026-06-27)**: 读 vue 渲染契约 + 调 API, 检查字段完整性 (~2s) | (new) |
|
||||
| ~~`dacli test check --formId=X`~~ | **v0.11+ 已删**: schema 完整性已被 webapi 镜像自动保证 | — |
|
||||
|
||||
**何时用 test**:
|
||||
- 阶段 5 测试 (v0.11+ 推荐): `dacli test run` + `dacli test check` 不需浏览器, 跑得快 (~5s vs 30s+)
|
||||
- 浏览器层 E2E 仍保留作为可选 visual regression (ssw-e2e-test)
|
||||
- **局限**: 不验浏览器 vmodel bind bug (tdd10 浏览器只 bind 2 字段 bug, 此工具查不出)
|
||||
- **API 层**: `dacli test run` (POST/GET/PUT/DELETE, ~5s)
|
||||
- **源码渲染层** (★ 推荐替代浏览器): `dacli test render --module=dict` 读 web 端 .vue 渲染契约 + 调 API, ~2s 完成, 不需 playwright
|
||||
- **Schema 层**: webapi 镜像自动保证 (BS-51/52/54)
|
||||
- **浏览器层**: `dacli test gen` 生成脚本, 用户手动跑; 或 ssw-e2e-test 仍作为 visual regression
|
||||
- **局限**: `test render` 查不出 vmodel bind bug / 控件渲染异常 (浏览器 JS) → 这些仍需 ssw-e2e-test
|
||||
- 替代 4 个散落 `tests/test-webapi-*.ts` 脚本
|
||||
- **命名说明**: 主命令 `dacli test`, 对齐 `npm test` / `pytest` / `go test` 惯例. 早期 v0.11+ 命名为 `testcase`, 已统一为 `test`.
|
||||
|
||||
**`test render` 详细说明** (★ 替代浏览器验证):
|
||||
- 算法: `@vue/compiler-sfc` 解析 web/.../sysData/dictionary/{index,Form,components/index,components/Form}.vue
|
||||
- list mode: 提取 `BasicColumn[].dataIndex` (列表渲染字段)
|
||||
- form mode: 提取 `useForm({schemas:[{field}]}).field` (表单渲染字段)
|
||||
- 调对应 API 拿当前数据
|
||||
- 对比: 渲染字段 ⊆ API 字段 ? PASS : FAIL
|
||||
- 覆盖 4 个页面 (dict module):
|
||||
- 字典类型列表 (vue: components/index.vue + API: GET /DictionaryType)
|
||||
- 字典数据列表 (vue: index.vue + API: GET /DictionaryData/{typeId})
|
||||
- 字典类型编辑表单 (vue: components/Form.vue + API: GET /DictionaryType/{id})
|
||||
- 字典数据编辑表单 (vue: Form.vue + API: GET /DictionaryData/{id}/Info)
|
||||
- B 铁律对应: B1 列表渲染 / B2 表单渲染 / B3 详情渲染 / B4 更新后状态
|
||||
- 用法示例:
|
||||
```bash
|
||||
dacli test render --module=dict # 仅验证类型列表
|
||||
dacli test render --module=dict --typeId=840592399989211141 # + 验证某类型数据列表
|
||||
dacli test render --module=dict --typeId=X --id=Y # + 验证某条数据表单
|
||||
dacli test render --module=dict --json | jq '.results[].status' # 批量跑
|
||||
```
|
||||
- Phase B 计划: form / menu / workflow / di 等模块
|
||||
|
||||
## 📚 详细文档(按需加载,按用途查 references/)
|
||||
|
||||
> **🧹 v0.11+ 收纳 (2026-06-27)**: 原 12 个独立技能(form-development / menu-configuration /
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
"""
|
||||
Batch 1 TC-B 浏览器截图脚本 (tdd1 字典管理)
|
||||
- 3 张截图: dict-list / dict-create-modal / dict-data-detail
|
||||
- B 铁律 1-4 验证
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
import time
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, "/home/ubuntu/ccWorkDir/.claude/skills/ssw-e2e-test/scripts")
|
||||
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
OUT = Path("/home/ubuntu/ccWorkDir/docs/tds/tdd1-batch1-screenshots")
|
||||
OUT.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
DICT_URL = "http://nginx/sysData/dictionary"
|
||||
|
||||
results = {"screenshots": [], "iron_laws": {}}
|
||||
|
||||
|
||||
def main():
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch(headless=True, args=["--no-sandbox"])
|
||||
context = browser.new_context(viewport={"width": 1440, "height": 900})
|
||||
page = context.new_page()
|
||||
|
||||
# ====== 登录 ======
|
||||
page.goto("http://nginx/", wait_until="domcontentloaded", timeout=30000)
|
||||
time.sleep(2)
|
||||
# 触发 JNPF 单点登录 (admin/123456)
|
||||
try:
|
||||
# 直接填账号密码
|
||||
page.fill('input[placeholder*="账"], input[placeholder*="user"]', "admin")
|
||||
page.fill('input[type="password"]', "123456")
|
||||
page.click('button:has-text("登录"), button:has-text("登 录"), button[type="submit"]')
|
||||
time.sleep(3)
|
||||
except Exception as e:
|
||||
print(f"[WARN] login fill failed: {e}, 尝试直接访问字典页")
|
||||
|
||||
# ====== 跳字典管理 ======
|
||||
page.goto(DICT_URL, wait_until="domcontentloaded", timeout=30000)
|
||||
time.sleep(4)
|
||||
|
||||
# ====== 截图 1: 字典列表 ======
|
||||
time.sleep(2) # 等待列表渲染
|
||||
shot1 = OUT / "dict-list.png"
|
||||
page.screenshot(path=str(shot1), full_page=False)
|
||||
results["screenshots"].append(str(shot1))
|
||||
|
||||
# ====== 先点左侧 tds.security.level 类型 (使 add 按钮可用) ======
|
||||
type_clicked = False
|
||||
try:
|
||||
# 遍历左侧树节点找含 tds.security.level 的
|
||||
all_nodes = page.locator('.jnpf-content-wrapper-left .ant-tree-node-content-wrapper, .left-tree .node-label, .tree-content li')
|
||||
cnt = all_nodes.count()
|
||||
for i in range(cnt):
|
||||
try:
|
||||
txt = all_nodes.nth(i).inner_text()
|
||||
if "tds.security.level" in txt or ("数据安全分级" in txt and "Batch" not in txt):
|
||||
all_nodes.nth(i).click()
|
||||
type_clicked = True
|
||||
time.sleep(2)
|
||||
break
|
||||
except Exception:
|
||||
continue
|
||||
results["iron_laws"]["B0_type_selected"] = type_clicked
|
||||
except Exception as e:
|
||||
results["iron_laws"]["B0_type_selected"] = f"err: {e}"
|
||||
|
||||
# B 铁律 1: 含新增按钮
|
||||
try:
|
||||
btn_add = page.locator('button.ant-btn-primary i.icon-ym-btn-add, a-button button.ant-btn-primary:has(i.icon-ym-btn-add)').first
|
||||
has_add = btn_add.count() > 0
|
||||
if not has_add:
|
||||
# fallback: 任何 ant-btn-primary 在 tableTitle 内
|
||||
btn_add = page.locator('.jnpf-content-wrapper-center button.ant-btn-primary').first
|
||||
has_add = btn_add.count() > 0
|
||||
results["iron_laws"]["B1_has_add_btn"] = has_add
|
||||
except Exception as e:
|
||||
results["iron_laws"]["B1_has_add_btn"] = f"err: {e}"
|
||||
|
||||
# ====== 点新增按钮 (B 铁律 2) ======
|
||||
clicked = False
|
||||
try:
|
||||
btn_add = page.locator('.jnpf-content-wrapper-center button.ant-btn-primary').first
|
||||
if btn_add.count() > 0:
|
||||
btn_add.click(timeout=5000)
|
||||
clicked = True
|
||||
time.sleep(2)
|
||||
except Exception as e:
|
||||
results["iron_laws"]["B2_click_add"] = f"err: {e}"
|
||||
|
||||
results["iron_laws"]["B2_click_add"] = clicked
|
||||
|
||||
# ====== 截图 2: 新增字典弹窗 ======
|
||||
shot2 = OUT / "dict-create-modal.png"
|
||||
page.screenshot(path=str(shot2), full_page=False)
|
||||
results["screenshots"].append(str(shot2))
|
||||
|
||||
# 关掉弹窗
|
||||
try:
|
||||
page.keyboard.press("Escape")
|
||||
time.sleep(1)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# ====== 截图 3: 字典项详情 (L1/L2/L3/L4 已加载到右侧表) ======
|
||||
time.sleep(2)
|
||||
shot3 = OUT / "dict-data-detail.png"
|
||||
page.screenshot(path=str(shot3), full_page=False)
|
||||
results["screenshots"].append(str(shot3))
|
||||
|
||||
# B 铁律 4: 3 张 MD5 不能全相同
|
||||
import hashlib
|
||||
hashes = []
|
||||
for s in [shot1, shot2, shot3]:
|
||||
if s.exists():
|
||||
hashes.append(hashlib.md5(s.read_bytes()).hexdigest())
|
||||
results["iron_laws"]["B4_md5_hashes"] = hashes
|
||||
results["iron_laws"]["B4_all_different"] = len(set(hashes)) == len(hashes) if len(hashes) == 3 else False
|
||||
|
||||
browser.close()
|
||||
|
||||
print(json.dumps(results, ensure_ascii=False, indent=2))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user