Loading...
Loading...
Execute, validate, and debug Midscene YAML automation files. Handles dry-run, execution, report analysis, and iterative debugging.
npx skill4agent add lee-117/midi-stagehand-skill midscene-runnernode 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 chrome# Linux/macOS
export PUPPETEER_EXECUTABLE_PATH="/path/to/chrome"
# Windows PowerShell
$env:PUPPETEER_EXECUTABLE_PATH="C:\path\to\chrome.exe"| Platform | Dependencies |
|---|---|
| Web | Chrome/Chromium browser (auto-detected, see above instructions) |
| Android | ADB-connected device (verify with |
| iOS | WebDriverAgent configured |
| Extended mode | |
npm install && npm run setup./midscene-output/./templates/.yaml.ymlnode 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.js# Single file execution
node scripts/midscene-run.js <yaml-file> [options]
# Batch execution (glob pattern)
node scripts/midscene-run.js "tests/**/*.yaml"scripts/midscene-run.js@midscene/web# Installation (first time only)
npm install @midscene/web dotenv
# Execute with UI (recommended for debugging)
npx @midscene/web <yaml-file> --headed
# Batch execution (official CLI option)
npx @midscene/web "tests/**/*.yaml" --concurrent --continue-on-errorNote: The package name is(not@midscene/web). The official CLI syntax is@midscene/cli, which supports thenpx @midscene/web <yaml-file>subcommand (run); both forms are acceptable.npx @midscene/web run <yaml-file>
--dry-runMIDSCENE_MODEL_API_KEY--timeout <ms>--output-ts <path>--dry-run--report-dir <path>./midscene-report--template puppeteer|playwright--verbose-v--help-h--output-tsnode scripts/midscene-run.js test.yaml --output-ts ./debug-output.tsaiQueryoutputWhat 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# Basic execution
node scripts/midscene-run.js test.yaml
# Validate only, no execution
node scripts/midscene-run.js test.yaml --dry-run
# Save generated TS (Extended mode only)
node scripts/midscene-run.js test.yaml --output-ts ./output.ts
# Use Playwright template
node scripts/midscene-run.js test.yaml --template playwright
# Specify report directory
node scripts/midscene-run.js test.yaml --report-dir ./reports
# Set timeout to 10 minutes
node scripts/midscene-run.js test.yaml --timeout 600000
# Validate + save TS (troubleshoot transpilation issues)
node scripts/midscene-run.js test.yaml --dry-run --output-ts ./debug.ts
# View help
node scripts/midscene-run.js --help# Execute with UI (recommended for debugging)
npx @midscene/web test.yaml --headed
# Headless execution (recommended for CI/CD)
npx @midscene/web test.yamlagent:
testId: "test-001"
groupName: "Regression Test"
groupDescription: "Daily regression test suite"
cache: truetasks:
- name: Task A
continueOnError: true
flow: [...]
- name: Task B (executes even if A fails)
flow: [...]# Full Web platform configuration
web:
url: "https://example.com"
headless: false # true = headless mode (suitable for CI/CD); false = UI mode (suitable for debugging)
viewportWidth: 1920 # Default 1280; use 375 for mobile simulation
viewportHeight: 1080 # Default 720; use 667 for mobile simulation
userAgent: "Custom User Agent"
waitForNetworkIdle:
timeout: 2000
continueOnNetworkIdleError: true
# Android platform (ensure device is connected via adb first)
android:
deviceId: "emulator-5554" # Device ID from adb devices output
# Use launch: "com.example.app" in flow to start the app
# iOS platform (WebDriverAgent must be configured first)
ios:
wdaPort: 8100 # WebDriverAgent port
wdaHost: "localhost" # WebDriverAgent host
# Use launch: "com.example.app" in flow to start the appaiWaitForaiAssert--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-code./midscene-output/