Files
claude-config/hooks/playwright-ai-cli.js
ssw fee91b6ccc v16: 迁移 playwright-cli → playwright Node.js 包 + AI wrapper
playwright-cli (2026-06-15 @playwright/cli 废弃):
- init.js / init.sh 移除 @playwright/cli 安装+软链步骤
- npm install -g playwright (Node.js 包) 替代 @playwright/cli
- 本地 5 行 wrapper .claude/hooks/playwright-ai-cli.js 复刻 @playwright/cli
  (用 playwright-core/lib/tools/cli-client/program 入口, 零额外依赖)
- /usr/local/bin/playwright → 软链到 wrapper
- 标准 test/codegen 走 npx playwright (npm bin 仍可用)

文档/命令:
- CLAUDE.md, ssw-test.md, ssw-h5dev-flow.md, ssw-e2e-test/SKILL.md,
  troubleshooting, api-test 全部 playwright-cli → playwright
- auto-push-on-stop.sh JUNK_PATTERNS 加 .playwright/ 目录过滤

验证 (per 用户"注意验证有效性"):
- node init.js / bash init.sh 幂等通过 (再跑也 OK)
- playwright --version 返 1.60.0
- playwright -s=smoke open/snapshot/click/close 全部工作
- snapshot YAML 输出含 ref (e1/e2/e3), AI 可直接用
- 标准 CLI 仍可达: npx playwright --version
2026-06-15 11:56:39 +08:00

38 lines
1.7 KiB
JavaScript
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/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 <args> # 直调标准 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 });