Files
claude-config/commands/ssw-test.md
T
ssw a502419b8f v17: JNPF 标准库用法写入相关技能 (标注仅 jnpf 平台有效)
ssw-e2e-test/SKILL.md (+191 行, 744 → 935):
- 新增 "⚠️ 平台专用声明" (顶部, 红字)
- 新增 "🎯 v17 JNPF 浏览器验证标准库" 段 (前置依赖后, playwright 模式前):
  * 双语言实现: TS (dacli/tests/e2e/_helpers/) + Python (scripts/lib/)
  * API 速查卡 (15 个核心 API 一图览)
  * 端到端示例 (3 步 CRUD, 13 行 TS + 13 行 Python)
  * 验证记录 (8/8 PASS in 42.5s + 42.8s)
  * jnpf 6.2.0 关键契约 (selectors 常量摘要)
  * JNPF 路由规则: 功能表单 /model/<enCode> vs 流程 workFlow/...
  * 查 model/X 菜单 API 正确用法 (ModuleBySystem 不是 ModuleTree)
  * 已废弃/将替换 清单

ssw-test.md (+18 行):
- "🎯 v17 JNPF 标准库" 段
- 强调仅 JNPF 平台有效
- 引用 ssw-e2e-test/SKILL.md 详细段
- 列核心 API 快速入口

ssw-h5dev-flow.md (阶段 5 E2E 测试行):
- 改推荐用 v17 标准库
- 标注仅 JNPF 平台有效

memory/jnpf-browser-verification-stdlib.md (上轮已加, 本轮不动)

后续 (留 v18+):
- 用 lib 重写 jnpf_browser_e2e.py 简化 (-50%)
- JNPF 浏览器验证标准库 (TS+Python) 持续补充
2026-06-15 16:06:41 +08:00

6.4 KiB
Raw Blame History

skill, description, triggerWords, autoTrigger
skill description triggerWords autoTrigger
ssw-e2e-test JNPF E2E + API 测试(基于 playwright Node.js + curl + dacli)
ssw-test
e2e
表单测试
功能测试
测试表单
e2e测试
浏览器测试
api测试
false

SSW E2E + API Testing

JNPF 测试工具集:

  • UI 自动化:playwright Node.js 版 CLI 直接调(无 dacli 包装)
  • API 验证:curl + jq + dacli 业务命令

📦 2026-06-05 变更:dacli 不再包装 curl / playwright(移除 dacli test / dacli e2e)。

📦 2026-06-15 变更:从 @playwright/cli 迁移到 playwright Node.js 包,命令 playwright-cli → playwright(同一 playwright-core CLI program,session 模式 playwright -s=X ... 不变)。

双模式测试架构

场景 工具 说明
浏览器 UI 自动化 playwright -s=dacli ... Playwright Node.js 版 CLI,UI 操作测试
API 验证 curl + jq + dacli <业务命令> 调 JNPF 后端接口

🎯 v17 JNPF 标准库(仅 JNPF 平台有效)

⚠️ 平台专用:以下库依赖 JNPF 6.2.0 稳定契约 (.jnpf-menu-item / .vxe-body--row / /model/<enCode> 路由) 和 jnpf 后端 urlAddress 构造机制,仅在测试 JNPF 平台上开发的应用时使用,不要套到非 jnpf 项目。

详见 .claude/skills/ssw-e2e-test/SKILL.md 🎯 v17 JNPF 浏览器验证标准库 段(双语言 API 速查 + 端到端示例 + 验证记录)。

快速入口:

  • TypeScript (playwright test): import { ... } from '../_helpers' (来自 dacli/tests/e2e/_helpers/)
  • Python (ad-hoc 脚本): from lib import ... (来自 .claude/skills/ssw-e2e-test/scripts/lib/)

核心 API: clickMenu / clickAdd / fillByLabel / selectByLabel / fillDateByLabel / fillTextareaByLabel / fillNumberByLabel / saveModal / closeModal / countRows / findRow / clickRowAction / waitTableReady / waitFormModalReady / waitRowCountChange / getErrors

playwright 基本模式

所有调用都用 -s=dacli 共享 session:

# 启动
playwright -s=dacli open "http://nginx/jnpf_app_tds/login"

# 登录
playwright -s=dacli fill "#form_item_account" "admin"
playwright -s=dacli fill "#form_item_password" "123456"
playwright -s=dacli click "button:has-text('登 录')"

# 菜单/点击/填写/截图
playwright -s=dacli click ".jnpf-menu-item:has-text('用户管理')"
playwright -s=dacli fill "#f_name" "测试值"
playwright -s=dacli screenshot "/tmp/screen.png"

# 执行 JS
playwright -s=dacli eval "() => document.title"

# 控制台
playwright -s=dacli console

# 关闭
playwright -s=dacli close

底层子命令:open, goto, click, fill, select, eval, type, console, snapshot

curl + jq API 测试

前置:dacli 登录获取 token

# 登录
dacli app login --account=admin --password=123456 --appCode=tds

# 取 token
TOKEN=$(jq -r .token $ccWorkDir/.dacli-token/token.json)
APP_CODE=$(jq -r .appCode $ccWorkDir/.dacli-token/token.json)
BASE="http://127.0.0.1:30000"

# GET 列表
curl -s "$BASE/api/visualdev/Base/list" -H "App-Code: $APP_CODE" -H "Authorization: $TOKEN" | jq .

# POST 创建
curl -s -X POST "$BASE/api/visualdev/Base" \
  -H "App-Code: $APP_CODE" -H "Authorization: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"fullName":"测试","enCode":"test","table":"test"}' | jq .

# 取 ID
FORM_ID=$(curl -s "$BASE/api/visualdev/Base/list?keyword=test" \
  -H "App-Code: $APP_CODE" -H "Authorization: $TOKEN" | jq -r '.data.list[0].id')

# 详情
curl -s "$BASE/api/visualdev/Base/$FORM_ID" \
  -H "App-Code: $APP_CODE" -H "Authorization: $TOKEN" | jq .

用 dacli 业务命令(推荐)

业务命令 = 一行 curl(自动拼好 headers/token/appCode):

业务命令 等价 curl
dacli form list curl /api/visualdev/Base/list
dacli form info --id=<id> curl /api/visualdev/Base/{id}
dacli form create --fullName=... (v0.7+: --name 改 --fullName) curl POST /api/visualdev/Base
dacli menu list curl /api/system/Menu/ModuleBySystem
dacli user list curl /api/permission/User/list
dacli tool logs --level=error curl /api/ssw/system/logs

常用 JS 模式(playwright eval)

点击菜单

() => {
  const items = document.querySelectorAll('.jnpf-menu-item');
  for (const item of items) {
    if (item.innerText.includes('目标菜单')) {
      item.click();
      return 'clicked: ' + item.innerText;
    }
  }
  return 'not found';
}

检测 Modal

() => !!document.querySelector('.ant-modal')

获取表单字段

() => {
  const fields = [];
  document.querySelectorAll('.ant-modal .ant-form-item').forEach(item => {
    const label = item.querySelector('.ant-form-item-label label')?.innerText;
    const id = item.querySelector('input,select')?.getAttribute('id');
    fields.push({ label, id });
  });
  return fields;
}

查找 vxe-table 行

() => {
  const rows = document.querySelectorAll('.vxe-body--row');
  for (const row of rows) {
    if (row.innerText.includes('目标文本')) return 'found';
  }
  return 'not found';
}

组合使用示例

# 1. 登录(API)
dacli app login --account=admin --password=123456 --appCode=tds

# 2. API 验证表单列表(curl + jq)
curl -s "http://127.0.0.1:30000/api/visualdev/Base/list" \
  -H "App-Code: tds" -H "Authorization: $TOKEN" | jq '.data.list | length'

# 3. UI 测试新增(playwright)
playwright -s=dacli open "http://nginx/jnpf_app_tds/"
playwright -s=dacli eval "() => {
  document.querySelectorAll('.jnpf-menu-item').forEach(item => {
    if (item.innerText.includes('数据资产')) { item.click(); return; }
  });
}"
playwright -s=dacli click "button:has-text('新 增')"
# ... 填写表单,保存 ...

# 4. API 验证数据
curl -s "http://127.0.0.1:30000/api/visualdev/Base/$FORM_ID" \
  -H "App-Code: tds" -H "Authorization: $TOKEN" | jq '.data | {id, fullName, state}'

常见问题

问题 解决
菜单点击无效 playwright -s=dacli eval + JS element.click()
下拉选项无法点击 用 playwright -s=dacli eval 取坐标后 mouse click
表格无数据 curl + jq 验证 API 返回
登录失败 dacli app login 先确保登录成功
密码加密 JNPF 前端用 MD5+AES 加密,dacli app login 自动处理