diff --git a/CLAUDE.md b/CLAUDE.md index 6c2c7b4..2550305 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -362,8 +362,8 @@ alias dacli='npx tsx $ccWorkDir/dacli/src/cli.ts' cd $ccWorkDir/dacli && npm install # 首次需装依赖 dacli app login --account=admin --password=123456 --appCode=developSystem -# E2E测试(playwright-cli) -cd $ccWorkDir/test && playwright-cli test --project=chromium +# E2E测试(playwright Node.js) +cd $ccWorkDir/test && npx playwright test --project=chromium ``` --- diff --git a/commands/ssw-h5dev-flow.md b/commands/ssw-h5dev-flow.md index 3fd7700..d382544 100644 --- a/commands/ssw-h5dev-flow.md +++ b/commands/ssw-h5dev-flow.md @@ -305,7 +305,7 @@ dacli app status # 确认登录状态 2. 根据测试用例逐项验证 3. **测试框架**: - API 集成测试:`curl + jq` 或 `dacli form/menu/... list`(无需启动前端,详见 `api-test` 技能) - - E2E 测试:`playwright-cli -s=dacli open ... && playwright-cli -s=dacli eval ...`(详见 `ssw-e2e-test` 技能) + - E2E 测试:`playwright -s=dacli open ... && playwright -s=dacli eval ...`(详见 `ssw-e2e-test` 技能) 4. 发现问题直接修复并验证,遇到平台、dacli相关问题、处理措施、建议、提示词优化写到 `$ccWorkDir/docs/{app_code}/debug.html` ### 阶段6: 总结 diff --git a/commands/ssw-test.md b/commands/ssw-test.md index b219f49..133c338 100644 --- a/commands/ssw-test.md +++ b/commands/ssw-test.md @@ -1,6 +1,6 @@ --- skill: ssw-e2e-test -description: JNPF E2E + API 测试(基于 playwright-cli + curl + dacli) +description: JNPF E2E + API 测试(基于 playwright Node.js + curl + dacli) triggerWords: [ssw-test, e2e, 表单测试, 功能测试, 测试表单, e2e测试, 浏览器测试, api测试] autoTrigger: false --- @@ -8,44 +8,46 @@ autoTrigger: false # SSW E2E + API Testing JNPF 测试工具集: -- **UI 自动化**:playwright-cli 直接调(无 dacli 包装) +- **UI 自动化**:playwright Node.js 版 CLI 直接调(无 dacli 包装) - **API 验证**:curl + jq + dacli 业务命令 -> 📦 **2026-06-05 变更**:dacli 不再包装 curl / playwright-cli(移除 `dacli test` / `dacli e2e`)。 +> 📦 **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-cli -s=dacli ...` | Playwright CLI,UI 操作测试 | +| 浏览器 UI 自动化 | `playwright -s=dacli ...` | Playwright Node.js 版 CLI,UI 操作测试 | | API 验证 | `curl + jq` + `dacli <业务命令>` | 调 JNPF 后端接口 | -## playwright-cli 基本模式 +## playwright 基本模式 **所有调用都用 `-s=dacli` 共享 session**: ```bash # 启动 -playwright-cli -s=dacli open "http://nginx/jnpf_app_tds/login" +playwright -s=dacli open "http://nginx/jnpf_app_tds/login" # 登录 -playwright-cli -s=dacli fill "#form_item_account" "admin" -playwright-cli -s=dacli fill "#form_item_password" "123456" -playwright-cli -s=dacli click "button:has-text('登 录')" +playwright -s=dacli fill "#form_item_account" "admin" +playwright -s=dacli fill "#form_item_password" "123456" +playwright -s=dacli click "button:has-text('登 录')" # 菜单/点击/填写/截图 -playwright-cli -s=dacli click ".jnpf-menu-item:has-text('用户管理')" -playwright-cli -s=dacli fill "#f_name" "测试值" -playwright-cli -s=dacli screenshot "/tmp/screen.png" +playwright -s=dacli click ".jnpf-menu-item:has-text('用户管理')" +playwright -s=dacli fill "#f_name" "测试值" +playwright -s=dacli screenshot "/tmp/screen.png" # 执行 JS -playwright-cli -s=dacli eval "() => document.title" +playwright -s=dacli eval "() => document.title" # 控制台 -playwright-cli -s=dacli console +playwright -s=dacli console # 关闭 -playwright-cli -s=dacli close +playwright -s=dacli close ``` 底层子命令:`open`, `goto`, `click`, `fill`, `select`, `eval`, `type`, `console`, `snapshot` @@ -94,7 +96,7 @@ curl -s "$BASE/api/visualdev/Base/$FORM_ID" \ | `dacli user list` | `curl /api/permission/User/list` | | `dacli tool logs --level=error` | `curl /api/ssw/system/logs` | -## 常用 JS 模式(playwright-cli eval) +## 常用 JS 模式(playwright eval) ### 点击菜单 ```javascript @@ -149,14 +151,14 @@ dacli app login --account=admin --password=123456 --appCode=tds 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-cli) -playwright-cli -s=dacli open "http://nginx/jnpf_app_tds/" -playwright-cli -s=dacli eval "() => { +# 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-cli -s=dacli click "button:has-text('新 增')" +playwright -s=dacli click "button:has-text('新 增')" # ... 填写表单,保存 ... # 4. API 验证数据 @@ -168,8 +170,8 @@ curl -s "http://127.0.0.1:30000/api/visualdev/Base/$FORM_ID" \ | 问题 | 解决 | |------|------| -| 菜单点击无效 | `playwright-cli -s=dacli eval` + JS `element.click()` | -| 下拉选项无法点击 | 用 `playwright-cli -s=dacli eval` 取坐标后 `mouse click` | +| 菜单点击无效 | `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` 自动处理 | diff --git a/hooks/auto-push-on-stop.sh b/hooks/auto-push-on-stop.sh index 95611aa..a2e2b2f 100755 --- a/hooks/auto-push-on-stop.sh +++ b/hooks/auto-push-on-stop.sh @@ -6,7 +6,7 @@ # # 设计原则: # 1. **保守优先** — 默认只 commit tracked 文件的修改/删除(git add -u), -# untracked 文件默认不推(防止 .playwright-cli/ 之类的历史遗留污染)。 +# untracked 文件默认不推(防止 .playwright-cli/ / .playwright/ 之类的历史遗留污染)。 # 2. **安全门** — 变更文件数 / 体积超过阈值就跳过 + 警告,不阻塞 Stop。 # 3. **失败兜底** — push 失败不阻塞 Claude 退出(脚本末尾 || true)。 # 4. **可观测** — 写日志到 .claude/logs/auto-push-{date}.log,每次 push 都有记录。 @@ -45,7 +45,7 @@ ALLOW_GLOBS="${AUTOPUSH_ALLOW_GLOBS:-}" # 路径黑名单:build/cache/状态类目录,绝不纳入 commit # (用 grep -E 模式,子串匹配路径中任一段即命中) -JUNK_PATTERNS='(/\.git/|/node_modules/|/target/|/build/|/dist/|/\.gradle/|/__pycache__/|/\.idea/|/\.vscode/|\.pnpm-store/|\.playwright-cli/|\.omc/|/\.claude/logs/|/\.playwright-mcp/|/history-bak/|/\.dacli-token/|/\.auth/|/test-results/|/playwright-report/|/screenshots/|\.DS_Store$|\.log$|\.swp$|~$|/tmp/)' +JUNK_PATTERNS='(/\.git/|/node_modules/|/target/|/build/|/dist/|/\.gradle/|/__pycache__/|/\.idea/|/\.vscode/|\.pnpm-store/|\.playwright-cli/|\.playwright/|\.omc/|/\.claude/logs/|/\.playwright-mcp/|/history-bak/|/\.dacli-token/|/\.auth/|/test-results/|/playwright-report/|/screenshots/|\.DS_Store$|\.log$|\.swp$|~$|/tmp/)' # 6 个 gitea 仓库(hardcoded:仅这 6 个会推) # - .claude 自身就是一个 gitea 仓库(gitea:3000/ssw/claude-config.git), diff --git a/hooks/init.js b/hooks/init.js index 49788fd..63ad475 100644 --- a/hooks/init.js +++ b/hooks/init.js @@ -4,9 +4,8 @@ * * 职责(全部幂等,可重复执行): * 1. 把 dacli 可执行入口放到 /usr/local/bin/dacli(TS 版 wrapper) - * 2. 保证 playwright Node.js 库(npm 包)已安装 - * 3. 保证 playwright-cli 软链可用(e2e 技能 ssw-e2e-test 兼容) - * 4. 保证 google-chrome 已就绪(playwright install chrome 兜底) + * 2. 保证 playwright Node.js 库(npm `playwright` 包)已安装 + bin 软链 + * 3. 保证 google-chrome 已就绪(playwright install chrome 兜底) * * 触发:Dockerfile CMD 链式调用,容器首次启动时执行一次 * 输出:每步一行状态(容器 stdout,docker logs 可看) @@ -15,11 +14,13 @@ * - 不阻塞 JNPF 启动:网络操作(npm install / playwright install)失败用 try/catch 兜底 * - 不删任何文件,幂等追加 alias(先 filter 清掉旧的同名行) * - * v15 变更(2026-06-12): - * - 改用 playwright Node.js 库(npm `playwright` 包),不再依赖 @playwright/cli - * - 用 Node.js 实现(原 init.sh 改薄包装,调用本文件) - * - Chrome 安装走 `npx playwright install chrome`(playwright 库自带 CLI) - * - playwright-cli 软链保留(ssw-e2e-test 技能仍用 `playwright-cli -s=dacli ...`) + * v16 变更(2026-06-15): + * - 移除 @playwright/cli 包依赖(彻底废弃) + * - 统一用 playwright Node.js 库(npm `playwright` 包)的 playwright-core 子模块 + * - AI session 模式走本地 wrapper:`$ccWorkDir/.claude/hooks/playwright-ai-cli.js` + * (5 行复刻 @playwright/cli:require playwright-core/lib/tools/cli-client/program + program()) + * - /usr/local/bin/playwright → 软链到 wrapper,覆盖 npm 标准 bin(标准 test/codegen 用 npx) + * - 验证:`playwright --version` 返 1.x;`playwright -s=X open URL` session 命令工作 */ const { execSync, spawnSync } = require('child_process'); @@ -32,8 +33,9 @@ const BASHRC = path.join(HOME, '.bashrc'); const DACLI_SRC = path.join(CCWORKDIR, 'dacli/src/cli.ts'); const DACLI_LINK = '/usr/local/bin/dacli'; const PLAYWRIGHT_LIB_DIR = '/usr/lib/node_modules/playwright'; -const PLAYWRIGHT_CLI_BIN = '/usr/lib/node_modules/@playwright/cli/playwright-cli.js'; -const PLAYWRIGHT_CLI_LINK = '/usr/local/bin/playwright-cli'; +const PLAYWRIGHT_BIN = path.join(PLAYWRIGHT_LIB_DIR, 'cli.js'); +const PLAYWRIGHT_LINK = '/usr/local/bin/playwright'; +const PLAYWRIGHT_AI_CLI = path.join(CCWORKDIR, '.claude/hooks/playwright-ai-cli.js'); const log = (msg) => console.log(`[init.js] ${msg}`); @@ -68,39 +70,50 @@ log(` ✅ ${tryExec('command -v dacli') || '(未在 PATH 中)'}`); // ==================== 2. playwright Node.js 库 ==================== log('② 检查 playwright Node.js 库 (npm `playwright`)'); -if (fs.existsSync(PLAYWRIGHT_LIB_DIR)) { - const version = tryExec('npx playwright --version') || '(unknown)'; - log(` ✅ 已存在: ${PLAYWRIGHT_LIB_DIR} (${version})`); +if (fs.existsSync(PLAYWRIGHT_BIN)) { + const version = tryExec('playwright --version') || tryExec('npx playwright --version') || '(unknown)'; + log(` ✅ 已存在: ${PLAYWRIGHT_BIN} (${version})`); } else { log(' ⏳ 安装 playwright Node.js 库 ...'); const r = spawnSync('npm', ['install', '-g', 'playwright'], { stdio: 'ignore' }); if (r.status === 0) { - const version = tryExec('npx playwright --version') || ''; + const version = tryExec('playwright --version') || tryExec('npx playwright --version') || ''; log(` ✅ 安装完成 (${version})`); } else { log(' ⚠️ 安装失败(继续,后续步骤不阻塞)'); } } -// ==================== 3. playwright-cli 软链(e2e 技能兼容) ==================== -log('③ 检查 playwright-cli 软链 (ssw-e2e-test 兼容)'); -if (fs.existsSync(PLAYWRIGHT_CLI_BIN)) { - if (fs.existsSync(PLAYWRIGHT_CLI_LINK)) { - log(` ✅ 软链已存在: ${PLAYWRIGHT_CLI_LINK}`); - } else { - try { - fs.symlinkSync(PLAYWRIGHT_CLI_BIN, PLAYWRIGHT_CLI_LINK); - log(` ✅ 软链已建`); - } catch (e) { - log(` ⚠️ 软链失败: ${e.message}`); - } +// ==================== 2.5. playwright bin 软链兜底 ==================== +// 优先指向本地 AI-friendly wrapper(session 模式),找不到时 fallback 到 npm 标准 bin +log('②.5 检查 playwright bin 软链 /usr/local/bin/playwright'); +const ensureSymlink = (target) => { + // 幂等:先尝试 unlink 旧软链/文件(无则忽略) + try { fs.unlinkSync(PLAYWRIGHT_LINK); } catch {} + try { + fs.symlinkSync(target, PLAYWRIGHT_LINK); + return true; + } catch (e) { + log(` ⚠️ 软链失败: ${e.message}`); + return false; + } +}; +if (fs.existsSync(PLAYWRIGHT_AI_CLI)) { + if (ensureSymlink(PLAYWRIGHT_AI_CLI)) { + log(` ✅ 软链已建: ${PLAYWRIGHT_LINK} → ${PLAYWRIGHT_AI_CLI}`); + log(` (AI wrapper: playwright -s=X open URL / snapshot / click / fill / eval / close)`); + } +} else if (fs.existsSync(PLAYWRIGHT_BIN)) { + if (ensureSymlink(PLAYWRIGHT_BIN)) { + log(` ⚠️ AI wrapper 不存在, fallback 到 npm 标准 bin(无 session 模式)`); + log(` 缺: ${PLAYWRIGHT_AI_CLI}`); } } else { - log(` ⚠️ 找不到 ${PLAYWRIGHT_CLI_BIN}(e2e 技能可能不可用)`); + log(` ⚠️ 找不到 playwright bin(e2e 技能可能不可用)`); } -// ==================== 4. Chrome 检测/安装 ==================== -log('④ 检查 google-chrome'); +// ==================== 3. Chrome 检测/安装 ==================== +log('③ 检查 google-chrome'); const chromeVer = tryExec('google-chrome --version'); if (chromeVer) { log(` ✅ ${chromeVer}`); diff --git a/hooks/init.sh b/hooks/init.sh index 1a2e47b..a544bdb 100755 --- a/hooks/init.sh +++ b/hooks/init.sh @@ -1,8 +1,9 @@ #!/bin/bash # init.sh - 容器初始化脚本(替代 SessionStart 的两个 hook) # 职责(全部幂等,可重复执行): -# 1. 把 dacli 可执行入口放到 /usr/local/bin/dacli(native 比 jar 新就软链 native,否则写 jar wrapper) -# 2. 保证 @playwright/cli + 软链 + Chrome 已就绪 +# 1. 把 dacli 可执行入口放到 /usr/local/bin/dacli(TS 版 wrapper) +# 2. 保证 playwright Node.js 库(npm `playwright`)已安装 + bin 软链 +# 3. 保证 google-chrome 已就绪(playwright install chrome 兜底) # # 触发:Dockerfile CMD 链式调用,容器首次启动时执行一次 # 输出:每步一行状态(容器 stdout,docker logs 可看) @@ -10,14 +11,20 @@ # 设计: # - 不阻塞 JNPF 启动:网络操作(npm install / playwright install)失败用 || true 兜底 # - 不删任何文件,幂等追加 alias(先 sed 清掉旧的同名行) +# +# v16 变更(2026-06-15): +# - 移除 @playwright/cli + 软链步骤(彻底废弃 @playwright/cli 包) +# - 统一用 playwright Node.js 库(npm `playwright`)的 bin +# - AI/skill 引用:`playwright-cli` → `playwright`(保持 -s=dacli session 共享模式) set -u # 不用 -e:单步失败要继续后续步骤 CCWORKDIR="/home/ubuntu/ccWorkDir" BASHRC="$HOME/.bashrc" DACLI_SRC="$CCWORKDIR/dacli/src/cli.ts" -PLAYWRIGHT_CLI_BIN="/usr/lib/node_modules/@playwright/cli/playwright-cli.js" -PLAYWRIGHT_CLI_LINK="/usr/local/bin/playwright-cli" +PLAYWRIGHT_LIB_DIR="/usr/lib/node_modules/playwright" +PLAYWRIGHT_BIN="$PLAYWRIGHT_LIB_DIR/cli.js" +PLAYWRIGHT_LINK="/usr/local/bin/playwright" log() { echo "[init.sh] $*"; } @@ -42,30 +49,37 @@ else fi log " ✅ $(command -v dacli 2>/dev/null || echo '(未在 PATH 中)')" -# ============ 2. @playwright/cli 检测/安装 ============ -log "② 检查 @playwright/cli" -if [ -f "$PLAYWRIGHT_CLI_BIN" ]; then - log " ✅ 已存在: $PLAYWRIGHT_CLI_BIN" +# ============ 2. playwright Node.js 库 检测/安装 ============ +log "② 检查 playwright Node.js 库 (npm \`playwright\`)" +if [ -f "$PLAYWRIGHT_BIN" ]; then + log " ✅ 已存在: $PLAYWRIGHT_BIN" else - log " ⏳ 安装 @playwright/cli ..." - npm uninstall -g playwright-cli >/dev/null 2>&1 || true - npm install -g @playwright/cli >/dev/null 2>&1 \ + log " ⏳ 安装 playwright Node.js 库 ..." + npm install -g playwright >/dev/null 2>&1 \ && log " ✅ 安装完成" \ || log " ⚠️ 安装失败(继续,后续步骤不阻塞)" fi -# ============ 3. playwright-cli 软链(让命令在 PATH 中可用) ============ -log "③ 检查 playwright-cli 软链" -if [ -L "$PLAYWRIGHT_CLI_LINK" ] && [ -e "$PLAYWRIGHT_CLI_LINK" ]; then - log " ✅ 软链已存在: $PLAYWRIGHT_CLI_LINK" +# ============ 2.5. playwright bin 软链兜底 ============ +# 优先指向本地 AI-friendly wrapper(session 模式),找不到时 fallback 到 npm 标准 bin +PLAYWRIGHT_AI_CLI="$CCWORKDIR/.claude/hooks/playwright-ai-cli.js" +log "②.5 检查 playwright bin 软链 /usr/local/bin/playwright" +if [ -f "$PLAYWRIGHT_AI_CLI" ]; then + ln -sf "$PLAYWRIGHT_AI_CLI" "$PLAYWRIGHT_LINK" 2>/dev/null \ + && log " ✅ 软链已建: $PLAYWRIGHT_LINK → $PLAYWRIGHT_AI_CLI" \ + && log " (AI wrapper: playwright -s=X open URL / snapshot / click / fill / eval / close)" \ + || log " ⚠️ 软链失败" +elif [ -f "$PLAYWRIGHT_BIN" ]; then + ln -sf "$PLAYWRIGHT_BIN" "$PLAYWRIGHT_LINK" 2>/dev/null \ + && log " ⚠️ AI wrapper 不存在, fallback 到 npm 标准 bin(无 session 模式)" \ + && log " 缺: $PLAYWRIGHT_AI_CLI" \ + || log " ⚠️ 软链失败" else - ln -sf "$PLAYWRIGHT_CLI_BIN" "$PLAYWRIGHT_CLI_LINK" 2>/dev/null \ - && log " ✅ 软链已建" \ - || log " ⚠️ 软链失败(继续)" + log " ⚠️ 找不到 playwright bin(e2e 技能可能不可用)" fi -# ============ 4. Chrome 检测/安装 ============ -log "④ 检查 google-chrome" +# ============ 3. Chrome 检测/安装 ============ +log "③ 检查 google-chrome" if command -v google-chrome >/dev/null 2>&1; then VER=$(google-chrome --version 2>/dev/null | awk '{print $3}') log " ✅ chrome $VER" diff --git a/hooks/playwright-ai-cli.js b/hooks/playwright-ai-cli.js new file mode 100755 index 0000000..1d2c772 --- /dev/null +++ b/hooks/playwright-ai-cli.js @@ -0,0 +1,37 @@ +#!/usr/bin/env node +/** + * playwright-ai-cli.js — AI 友好的 playwright CLI 包装(替代 @playwright/cli) + * + * 背景:v16 2026-06-15 迁移到 playwright Node.js 包。标准 `playwright` CLI + * (`/usr/lib/node_modules/playwright/cli.js` → `playwright/lib/program`) + * 只支持 test/codegen/screenshot 等一次性命令,不支持 session 模式 + * (`playwright -s=name open/snapshot/click/fill/eval/close`)。 + * + * session 模式来自 `playwright-core/lib/tools/cli-client/program`, + * 正是 @playwright/cli 用的入口(playwright-core 是 playwright 包的子模块)。 + * + * 做法:本文件 5 行复刻 @playwright/cli 的逻辑,直接 require playwright-core 的 + * cli-client program。安装位置 `/usr/lib/node_modules/playwright/ai-cli.js`, + * 由 init.js 软链到 /usr/local/bin/playwright,覆盖 npm 的标准 bin。 + * + * 用法不变: + * playwright --version + * playwright -s=dacli open URL + * playwright -s=dacli snapshot + * playwright -s=dacli click e10 + * playwright -s=dacli fill e21 "admin" + * playwright -s=dacli eval "() => document.title" + * playwright -s=dacli close + * + * 若需要标准 test/codegen/screenshot: + * npx playwright test + * npx playwright codegen URL + * node /usr/lib/node_modules/playwright/cli.js # 直调标准 bin + */ + +// 用绝对路径避免 Node 找不到全局模块(require 从 hooks 目录找 .claude/hooks/node_modules) +const path = require('path'); +const programModule = require('/usr/lib/node_modules/playwright/node_modules/playwright-core/lib/tools/cli-client/program.js'); +const playwrightPkg = require('/usr/lib/node_modules/playwright/package.json'); + +programModule.program({ embedderVersion: playwrightPkg.version }); diff --git a/skills/api-test/SKILL.md b/skills/api-test/SKILL.md index e554cac..76fa0fc 100644 --- a/skills/api-test/SKILL.md +++ b/skills/api-test/SKILL.md @@ -9,7 +9,7 @@ description: "api-test" API 测试使用 **curl + jq** 调 JNPF 后端,**dacli** 提供登录态和业务命令封装。 -**注意**:UI 自动化测试请使用 `ssw-e2e-test` 技能(基于原生 `playwright-cli`)。 +**注意**:UI 自动化测试请使用 `ssw-e2e-test` 技能(基于原生 `playwright` Node.js 版 CLI)。 --- @@ -157,9 +157,9 @@ fi ## 与 UI 测试配合 ```bash -# 1. UI 自动化新增(playwright-cli 直接调,详见 ssw-e2e-test) -playwright-cli -s=dacli open http://nginx/ -playwright-cli -s=dacli eval "() => document.title" +# 1. UI 自动化新增(playwright 直接调,详见 ssw-e2e-test) +playwright -s=dacli open http://nginx/ +playwright -s=dacli eval "() => document.title" # 2. API 验证数据 curl -s "http://127.0.0.1:30000/api/visualdev/Base/$ID" \ diff --git a/skills/ssw-e2e-test/SKILL.md b/skills/ssw-e2e-test/SKILL.md index fa093fd..1a75189 100644 --- a/skills/ssw-e2e-test/SKILL.md +++ b/skills/ssw-e2e-test/SKILL.md @@ -5,9 +5,11 @@ description: "ssw-e2e-test" # SSW E2E Testing -E2E testing toolkit for jnpf low-code platform using **playwright-cli** (直接调,不再走 `dacli e2e` 包装)。 +E2E testing toolkit for jnpf low-code platform using **playwright** Node.js 版 CLI(直接调,不再走 `dacli e2e` 包装)。 -> 📦 **2026-06-05 变更**:dacli 不再包装 playwright-cli(移除 `dacli e2e`)。**直接用 `playwright-cli -s=dacli ...`**,session 共享 `-s=dacli` 名字。 +> 📦 **2026-06-05 变更**:dacli 不再包装 playwright(移除 `dacli e2e`)。**直接用 `playwright -s=dacli ...`**,session 共享 `-s=dacli` 名字。 +> +> 📦 **2026-06-15 变更**:从 `@playwright/cli` 包迁移到 `playwright` Node.js 包(同一 `playwright-core` CLI program,命令完全兼容,session 模式 `playwright -s=X ...` 不变)。 --- @@ -19,11 +21,11 @@ E2E testing toolkit for jnpf low-code platform using **playwright-cli** (直接 # 1. 检测 Node.js node --version 2>/dev/null || echo "Node.js 未安装,请访问 https://nodejs.org/ 下载" -# 2. 检测 playwright-cli -playwright-cli --version 2>/dev/null || npm install -g @playwright/cli +# 2. 检测 playwright (Node.js 版) +playwright --version 2>/dev/null || npm install -g playwright # 3. 检测 Chromium 浏览器 -playwright-cli install chrome +playwright install chrome # 4. 检测中文字体(容器内中文 label 显示为方框□□□□,盲点 36) fc-list :lang=zh 2>/dev/null | grep -q "Noto Sans CJK" || apt-get install -y fonts-noto-cjk @@ -37,7 +39,7 @@ export PLAYWRIGHT_BROWSERS_PATH=/home/ubuntu/.cache/ms-playwright ### 容器内 Playwright 替代方案(盲点 35) -> 背景:容器内 `playwright-cli -s=dacli open` 可能失败 `Cannot read properties of undefined (reading 'launch')`(npm playwright 缺 chromium 二进制)。改用 Python `playwright.sync_api`: +> 背景:容器内 `playwright -s=dacli open` 可能失败 `Cannot read properties of undefined (reading 'launch')`(npm playwright 缺 chromium 二进制)。改用 Python `playwright.sync_api`: ```python from playwright.sync_api import sync_playwright @@ -60,22 +62,22 @@ with sync_playwright() as p: --- -## playwright-cli 基本模式 +## playwright 基本模式 **所有调用都用 `-s=dacli` 共享 session**(名字可自定义,但同一会话内必须一致): ```bash # 打开页面 -playwright-cli -s=dacli open "http://nginx/jnpf_app_tds/login" +playwright -s=dacli open "http://nginx/jnpf_app_tds/login" # 跳转到指定URL -playwright-cli -s=dacli goto "http://nginx/jnpf_app_tds/" +playwright -s=dacli goto "http://nginx/jnpf_app_tds/" # 关闭 -playwright-cli -s=dacli close +playwright -s=dacli close ``` -**注意**:如果 session 不存在或已关闭,先用 `playwright-cli -s=dacli open ` 启动。 +**注意**:如果 session 不存在或已关闭,先用 `playwright -s=dacli open ` 启动。 --- @@ -84,7 +86,7 @@ playwright-cli -s=dacli close ### 第一阶段:界面探索与计划生成 **流程**: -1. 启动浏览器:`playwright-cli -s=dacli open ` +1. 启动浏览器:`playwright -s=dacli open ` 2. 处理登录(如需) 3. 目标地址校验 4. 界面探索(表单/按钮/表格/弹窗/下拉) @@ -145,11 +147,11 @@ playwright-cli -s=dacli close "name": "用例名称", "steps": [ { - "cmd": "playwright-cli -s=dacli screenshot artifacts/e2e/runs/{runId}/screenshots/TC001-01-login.png", + "cmd": "playwright -s=dacli screenshot artifacts/e2e/runs/{runId}/screenshots/TC001-01-login.png", "desc": "截图登录页" }, { - "cmd": "playwright-cli -s=dacli fill #form_item_account admin", + "cmd": "playwright -s=dacli fill #form_item_account admin", "desc": "填写账号" } ], @@ -166,7 +168,7 @@ playwright-cli -s=dacli close ```markdown # E2E 执行报告 -**计划路径:** `docs/playwright-cli-plans/.json` +**计划路径:** `docs/playwright-plans/.json` **runId:** `` **执行时间:** <时间> @@ -189,7 +191,7 @@ artifacts/e2e/runs// ## 失败与修复 ### TC002 新增数据 -**失败命令:** `playwright-cli -s=dacli click ".ant-btn-primary"` +**失败命令:** `playwright -s=dacli click ".ant-btn-primary"` **错误:** `Error: Ref e50 not found` **原因:** Modal 未完全渲染,ref 过期 **修复:** 重新 snapshot 获取新 ref @@ -249,7 +251,7 @@ artifacts/e2e/runs// ``` Task → Is it a jnpf platform test? ├─ Yes → Use ssw-e2e-test skill (本技能) - │ ├─ Login/menu → playwright-cli -s=dacli click "..." + │ ├─ Login/menu → playwright -s=dacli click "..." │ ├─ 功能表单 (vxe-table) → JS patterns (Section 1-5) │ ├─ 门户页面 → JS patterns (Section 6) │ ├─ 大屏页面 → JS patterns (Section 7) @@ -282,10 +284,10 @@ jnpf 菜单存在于 DOM 但可能不可见,Playwright 的 `force=True` 无效 })() ``` -**playwright-cli 命令**: +**playwright 命令**: ```bash # 用 eval 执行上面 JS(通过 jnpf-menu-item 匹配) -playwright-cli -s=dacli eval "() => { +playwright -s=dacli eval "() => { const items = document.querySelectorAll('.jnpf-menu-item'); for (const item of items) { if (item.innerText.includes('数据资产台账')) { item.click(); return 'clicked'; } @@ -455,20 +457,20 @@ document.querySelector('.ant-select')?.click() // 失败! const select = document.querySelector('.ant-modal .ant-select'); if (!select) return 'no select'; const box = select.getBoundingClientRect(); - // 使用 playwright-cli 的 mouse.click 触发 + // 使用 playwright 的 mouse.click 触发 return `click at ${box.x + box.width/2}, ${box.y + box.height/2}`; })() ``` -playwright-cli 执行时通过 `click` 配合坐标触发: +playwright 执行时通过 `click` 配合坐标触发: ```bash # 取坐标 -COORDS=$(playwright-cli -s=dacli eval "() => { +COORDS=$(playwright -s=dacli eval "() => { const s = document.querySelector('.ant-modal .ant-select'); const b = s.getBoundingClientRect(); return [b.x + b.width/2, b.y + b.height/2]; }" | jq -c .) -playwright-cli -s=dacli mouse click $(echo $COORDS | jq -r '.[0]') $(echo $COORDS | jq -r '.[1]') +playwright -s=dacli mouse click $(echo $COORDS | jq -r '.[0]') $(echo $COORDS | jq -r '.[1]') ``` ### Radio Button 处理 @@ -517,10 +519,10 @@ playwright-cli -s=dacli mouse click $(echo $COORDS | jq -r '.[0]') $(echo $COORD ```bash # 1. 先创建数据 -playwright-cli -s=dacli open "http://nginx/jnpf_app_tds/数据资产管理" +playwright -s=dacli open "http://nginx/jnpf_app_tds/数据资产管理" # 2. 然后操作创建的数据 -playwright-cli -s=dacli click ".vxe-body--row:first" +playwright -s=dacli click ".vxe-body--row:first" # 3. 验证下游效果(使用 api-test 技能) curl ... @@ -607,11 +609,11 @@ curl ... ## 复杂场景 JS 脚本 -当内置命令无法满足时,使用 playwright-cli 的 eval 配合 JS 脚本: +当内置命令无法满足时,使用 playwright 的 eval 配合 JS 脚本: ```bash # 通过 stdin 传 JS -playwright-cli -s=dacli eval "$(cat /path/to/script.js)" +playwright -s=dacli eval "$(cat /path/to/script.js)" ``` ### 完整 CRUD 示例脚本 @@ -730,7 +732,7 @@ dacli_web_session.py restore --session=/tmp/tdd.json \ ``` ### 2. 菜单点击无效 -使用 playwright-cli `eval` 配合 JS `element.click()`,或 `playwright-cli -s=dacli click "selector"` +使用 playwright `eval` 配合 JS `element.click()`,或 `playwright -s=dacli click "selector"` ### 3. Modal 保存后不关闭 Modal 保持打开也可能是保存成功(检查行数是否增加) diff --git a/skills/troubleshooting/SKILL.md b/skills/troubleshooting/SKILL.md index 4d4d2c3..4bbe2f5 100644 --- a/skills/troubleshooting/SKILL.md +++ b/skills/troubleshooting/SKILL.md @@ -105,9 +105,9 @@ dacli tool logs --level=error --lines=100 # 2. 查 JNPF 错误码 grep -A 1 "MsgCode" /home/ubuntu/ccWorkDir/jnpf/后端/jnpf-common/jnpf-boot-common/jnpf-common-core/src/main/java/jnpf/constant/MsgCode.java -# 3. 浏览器 E2E 调试(playwright-cli 直接调) -playwright-cli -s=dacli eval "() => Array.from(document.querySelectorAll('.jnpf-menu-item')).map(e => e.innerText)" -playwright-cli -s=dacli console +# 3. 浏览器 E2E 调试(playwright 直接调) +playwright -s=dacli eval "() => Array.from(document.querySelectorAll('.jnpf-menu-item')).map(e => e.innerText)" +playwright -s=dacli console # 4. 直接调用 API(curl + jq) TOKEN=$(jq -r .token $ccWorkDir/.dacli-token/token.json)