Loading...
Loading...
Compare original and translation side by side
node scripts/health-check.js@midscene/webtsx.envMIDSCENE_MODEL_BASE_URL=https://dashscope.aliyuncs.com/compatible-mode/v1
MIDSCENE_MODEL_API_KEY=sk-your-key
MIDSCENE_MODEL_NAME=qwen-vl-max-latestnpm run setupsetup@midscene/webtsxProgram Files\Google\Chrome\Application\chrome.exe/Applications/Google Chrome.app/Contents/MacOS/Google Chrome/usr/bin/google-chrome/usr/bin/chromiumnpx puppeteer browsers install chromeundefinednode scripts/health-check.js@midscene/webtsx.envMIDSCENE_MODEL_BASE_URL=https://dashscope.aliyuncs.com/compatible-mode/v1
MIDSCENE_MODEL_API_KEY=sk-your-key
MIDSCENE_MODEL_NAME=qwen-vl-max-latestnpm run setupsetup@midscene/webtsxProgram Files\Google\Chrome\Application\chrome.exe/Applications/Google Chrome.app/Contents/MacOS/Google Chrome/usr/bin/google-chrome/usr/bin/chromiumnpx puppeteer browsers install chromeundefined
**平台特定前提条件**:
| 平台 | 依赖 |
|------|------|
| Web | Chrome/Chromium 浏览器(自动检测,见上方说明) |
| Android | ADB 已连接设备(`adb devices` 验证) |
| iOS | WebDriverAgent 已配置 |
| Extended 模式 | `tsx` 运行时(`npx tsx --version`) |
如果缺少依赖,提示用户安装:
```bash
npm install && npm run setup
**Platform-Specific Prerequisites**:
| Platform | Dependencies |
|----------|--------------|
| Web | Chrome/Chromium browser (auto-detected, see above instructions) |
| Android | ADB-connected device (verify with `adb devices`) |
| iOS | WebDriverAgent configured |
| Extended mode | `tsx` runtime (check with `npx tsx --version`) |
If dependencies are missing, prompt the user to install:
```bash
npm install && npm run setup./midscene-output/./templates/.yaml.yml./midscene-output/./templates/.yaml.ymlnode scripts/midscene-run.js <yaml-file> --dry-run| 常见错误 | 原因 | 修复建议 |
|---|---|---|
| YAML 语法错误 | 缩进不正确或格式问题 | 检查缩进,统一使用 2 空格 |
| 缺少平台配置 | 没有 web/android/ios/computer | 添加 |
| 缺少 tasks | 没有定义任务 | 添加 tasks 数组和 flow |
| 未声明 engine | 使用超集关键字但未标记 | 添加 |
| 变量未定义 | 引用了未声明的 | 在 variables 中声明变量 |
| 未声明 features | Extended 模式未列出使用的特性 | 添加 |
| 循环缺少必要字段 | repeat 缺 count、while 缺 condition | 补充对应必要字段 |
| 导入文件不存在 | import 引用的路径不正确 | 检查文件路径是否正确 |
node scripts/midscene-run.js <yaml-file> --dry-run| Common Error | Cause | Fix Suggestion |
|---|---|---|
| YAML syntax error | Incorrect indentation or formatting issues | Check indentation, use 2 spaces consistently |
| Missing platform configuration | No web/android/ios/computer configuration | Add |
| Missing tasks | No tasks defined | Add tasks array and flow |
| Undeclared engine | Used superset keywords but not marked | Add |
| Undefined variable | Referenced an undeclared | Declare variables in the variables section |
| Undeclared features | Extended mode did not list used features | Add |
| Missing required fields in loop | repeat lacks count, while lacks condition | Add the corresponding required fields |
| Imported file does not exist | Incorrect path referenced in import | Check if the file path is correct |
scripts/midscene-run.jsundefinedscripts/midscene-run.jsundefined
**方式 2: 直接使用 Midscene CLI**
如果在外部项目中(没有 `scripts/midscene-run.js`),直接使用 `@midscene/web`:
```bash
**Method 2: Use Midscene CLI Directly**
If in an external project (without `scripts/midscene-run.js`), use `@midscene/web` directly:
```bash
> **注意**: 包名是 `@midscene/web`(不是 `@midscene/cli`)。官方 CLI 语法是 `npx @midscene/web <yaml-file>`,支持 `run` 子命令(`npx @midscene/web run <yaml-file>`),两种形式均可。
**可用选项**(方式 1):
- `--dry-run` — 仅验证和转换,不实际执行(注意:不检测模型配置,AI 操作需配置 `MIDSCENE_MODEL_API_KEY`)
- `--timeout <ms>` — 执行超时(默认 300000 = 5 分钟)。长时间自动化场景可增大此值
- `--output-ts <path>` — 保存转换后的 TypeScript 文件(仅 Extended 模式)。排查转译错误时,建议配合 `--dry-run` 一起使用
- `--report-dir <path>` — 报告输出目录(默认 `./midscene-report`)
- `--template puppeteer|playwright` — 选择 TS 模板(默认 puppeteer;playwright 适合需要多浏览器兼容的场景)
- `--verbose` / `-v` — 显示详细输出(验证详情、检测信息、环境信息)
- `--help` / `-h` — 显示帮助信息
**Extended 模式的执行流程**:
1. YAML → Transpiler → TypeScript
2. TypeScript → tsx 运行时 → Playwright + Midscene SDK
3. 生成执行报告
可以使用 `--output-ts` 保存中间 TypeScript 文件以便调试:
```bash
node scripts/midscene-run.js test.yaml --output-ts ./debug-output.ts
> **Note**: The package name is `@midscene/web` (not `@midscene/cli`). The official CLI syntax is `npx @midscene/web <yaml-file>`, which supports the `run` subcommand (`npx @midscene/web run <yaml-file>`); both forms are acceptable.
**Available Options** (Method 1):
- `--dry-run` — Only validate and transform, do not execute (Note: Does not detect model configuration; AI operations require `MIDSCENE_MODEL_API_KEY` to be configured)
- `--timeout <ms>` — Execution timeout (default 300000 = 5 minutes). Increase this value for long-running automation scenarios
- `--output-ts <path>` — Save the transformed TypeScript file (Extended mode only). When troubleshooting transpilation errors, it is recommended to use with `--dry-run`
- `--report-dir <path>` — Report output directory (default `./midscene-report`)
- `--template puppeteer|playwright` — Select TS template (default puppeteer; playwright is suitable for scenarios requiring multi-browser compatibility)
- `--verbose` / `-v` — Show detailed output (validation details, detection information, environment information)
- `--help` / `-h` — Show help information
**Extended Mode Execution Flow**:
1. YAML → Transpiler → TypeScript
2. TypeScript → tsx runtime → Playwright + Midscene SDK
3. Generate execution report
You can use `--output-ts` to save the intermediate TypeScript file for debugging:
```bash
node scripts/midscene-run.js test.yaml --output-ts ./debug-output.tsaiQueryoutputaiQueryoutput错误消息包含什么?
├─ "API key" / "401" / "Unauthorized"
│ → 模型未配置。设置 MIDSCENE_MODEL_API_KEY 环境变量或 .env 文件
│
├─ "Timeout" / "exceeded"
│ ├─ 页面能在浏览器中正常打开?
│ │ ├─ 是 → 页面加载慢,增加 timeout 值(如 timeout: 30000)
│ │ └─ 否 → 检查 URL 是否正确、网络是否可达
│ └─ 出现在 aiWaitFor?→ 条件描述可能不准确,检查 assertion 文本
│
├─ "Element not found" / "not found"
│ ├─ 第一次就失败?→ AI 描述不够精确,改用更具体的文字描述
│ ├─ 之前能成功?→ 页面结构可能变了,查看报告截图对比
│ └─ 仍然失败?→ 尝试 deepThink: true 或改用 xpath 定位
│
├─ "Assertion failed"
│ → 查看报告截图,对比实际页面状态 vs 预期描述,调整 aiAssert 文本
│
├─ "Navigation failed" / "net::ERR_"
│ → 检查 URL 协议(https://)和可访问性
│
├─ "Transpiler error"
│ → 使用 --dry-run --output-ts ./debug.ts 查看生成的代码排查语法问题
│
├─ "Permission denied"
│ → 页面需要登录或特殊权限,添加登录步骤或 cookie 配置
│
└─ "javascript" 步骤报错
→ 检查 JS 代码语法,注意浏览器环境 vs Node 环境的 API 差异--dry-runWhat does the error message contain?
├─ "API key" / "401" / "Unauthorized"
│ → Model not configured. Set the MIDSCENE_MODEL_API_KEY environment variable or .env file
│
├─ "Timeout" / "exceeded"
│ ├─ Can the page open normally in the browser?
│ │ ├─ Yes → Page loads slowly, increase the timeout value (e.g., timeout: 30000)
│ │ └─ No → Check if the URL is correct and network is reachable
│ └─ Occurs in aiWaitFor? → Condition description may be inaccurate, check assertion text
│
├─ "Element not found" / "not found"
│ ├─ Failed on first attempt? → AI description is not precise enough, use more specific text descriptions
│ ├─ Succeeded before? → Page structure may have changed, compare with report screenshots
│ └─ Still failing? → Try deepThink: true or use xpath positioning instead
│
├─ "Assertion failed"
│ → View report screenshots, compare actual page state vs expected description, adjust aiAssert text
│
├─ "Navigation failed" / "net::ERR_"
│ → Check URL protocol (https://) and accessibility
│
├─ "Transpiler error"
│ → Use --dry-run --output-ts ./debug.ts to view generated code and troubleshoot syntax issues
│
├─ "Permission denied"
│ → Page requires login or special permissions, add login steps or cookie configuration
│
└─ "javascript" step error
→ Check JS code syntax, note API differences between browser environment and Node environment--dry-run./midscene-report/recordToReportTotal : N
Passed: N
Failed: N
Status: passed|failed./midscene-report/recordToReportTotal : N
Passed: N
Failed: N
Status: passed|failedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedagent:
testId: "test-001"
groupName: "回归测试"
groupDescription: "每日回归测试套件"
cache: trueagent:
testId: "test-001"
groupName: "Regression Test"
groupDescription: "Daily regression test suite"
cache: truetasks:
- name: 任务 A
continueOnError: true
flow: [...]
- name: 任务 B(即使 A 失败也会执行)
flow: [...]tasks:
- name: Task A
continueOnError: true
flow: [...]
- name: Task B (executes even if A fails)
flow: [...]undefinedundefinedundefinedundefinedaiWaitForaiAssert--output-tsdeepThink: truexpathjavascriptrecordToReportaiWaitForaiAssert--output-tsdeepThink: truejavascriptrecordToReportnpm install.env${ENV:NAME}${ENV.NAME}parallelaiQuerymerge_results: true--dry-runnpx skills checknpx skills add https://github.com/lee-117/midi-stagehand-skill -a claude-codenpm install.env${ENV:NAME}${ENV.NAME}parallelaiQuerymerge_results: true--dry-runnpx skills checknpx skills add https://github.com/lee-117/midi-stagehand-skill -a claude-code./midscene-output/./midscene-output/