npx skills add ...
npx skills add web-infra-dev/midscene-skills --skill vitest-midscene-e2e
Enhances Vitest with Midscene for AI-powered UI testing across Web (Playwright), Android (ADB), and iOS (WDA). Scaffolds new projects, converts existing projects, and creates/updates/debugs/runs E2E tests using natural-language UI interactions. Triggers: write test, add test, create test, update test, fix test, debug test, run test, e2e test, midscene test, new project, convert project, init project, 写测试, 加测试, 创建测试, 更新测试, 修复测试, 调试测试, 运行测试, 新建工程, 转化工程.
npx skills add web-infra-dev/midscene-skills --skill vitest-midscene-e2e
| Module | Role |
|---|---|
| Vitest | TypeScript test framework. Provides describe/it/expect/hooks for test organization, assertions, and lifecycle. |
| Midscene | AI-driven UI automation. Interacts with UI elements via natural language — no fragile selectors. Core API: aiAct. |
Supported platforms:
WebTest (Playwright Chromium): ctx.agent + ctx.pageAndroidTest (ADB + scrcpy): ctx.agent onlyIOSTest (WebDriverAgent): ctx.agent onlyThe boilerplate at ~/.midscene/boilerplate/vitest-all-platforms-demo/ is the canonical reference for project structure, configs, platform context classes, and test conventions. Compare the current project against it. If anything is missing, ask the user which platform(s) they need (Web / Android / iOS), then fill in what's missing using the boilerplate as the target state. Only include files for the requested platform(s). Do NOT overwrite existing configs or files. Copy .env.example from the boilerplate as .env if it doesn't exist, and prompt the user to fill in the env vars.
It contains mandatory rules for using aiAct — the primary API for all UI operations. Do NOT skip this step.
Use the boilerplate's e2e/ directory and src/context/ as reference for patterns and conventions. Before running tests, ensure dependencies are installed and .env is configured. When debugging failures, check troubleshooting.md.
ctx.agent is a platform-specific agent instance. All methods return Promises.
PlaywrightAgent from @midscene/web/playwrightAndroidAgent from @midscene/androidIOSAgent from @midscene/iosAll three agents share the same AI methods below.
aiAct for User-Described StepsWhen the user describes a UI action or state confirmation in natural language, you MUST use
aiActto implement it. Do NOT decompose user instructions intoaiTap/aiInput/aiAssertor other fine-grained APIs. Pass the user's intent directly toaiActand let Midscene's AI handle the planning and execution.
Assertions, data extraction, and waiting should also be done via aiAct — it handles all of these. Do NOT use aiAssert, aiQuery, aiWaitFor, aiTap, or aiInput separately.
aiAct is the primary API for all UI operations and state confirmations. It accepts natural language instructions and autonomously plans and executes multi-step interactions.
When an aiAct prompt asks Midscene to upload files, pass fileChooserAllowedDir explicitly. Use the smallest directory containing that test case's fixtures, and refer to files relative to it in the prompt. Do not use the project root or a home directory. Replace ./fixtures below with the fixture directory relative to the test process working directory.
Phase splitting: If the task prompt is too long or covers multiple distinct stages, split it into separate aiAct calls — one per phase. Each phase should be a self-contained logical step, and all phases combined must match the user's original intent.
aiActionis deprecated. UseaiActoraiinstead.
'button' is ambiguous; use 'the blue "Submit" button at the top of the page'aiAction — use aiAct instead'the delete button in the first product row'aiActionContextaiActionContext is a system prompt string appended to all AI actions performed by the agent. Use it to define the AI's role and expertise.
Good examples:
'You are a Web UI testing expert.''You are an Android app testing expert who is familiar with Chinese UI.'Bad examples:
'Click the login button.' — specific actions belong in aiAct(), not aiActionContext'The page is in Chinese.' — this is page description, not a system promptnode_modules/@midscene/web, node_modules/@midscene/android, and node_modules/@midscene/ios, find the type definitions for the agent classes.d.ts files to read the implementation code in node_modulesgrep to search for the API or concept you need (the file is large, do not read it in full)