vitest-midscene-e2e
web-infra-dev/midscene-skills
AI-powered E2E testing for Web, Android, and iOS using natural-language UI interactions with Vitest and Midscene.
What is vitest-midscene-e2e?
Enhances Vitest with Midscene to enable AI-driven end-to-end testing across Web (Playwright), Android (ADB), and iOS (WDA) platforms. Use this when you need to write or maintain UI tests that interact with applications through natural-language descriptions rather than fragile selectors, and to scaffold or convert projects for multi-platform testing.
- Create and update E2E tests using natural-language UI interactions via the `aiAct` API
- Support Web (Playwright), Android (ADB), and iOS (WDA) platforms from a single test framework
- Scaffold new Vitest+Midscene projects and convert existing projects to include Midscene testing
- Debug and run E2E tests with AI-driven UI automation that handles multi-step interactions
- Extract data and verify UI state using natural-language assertions instead of brittle selectors
How to install vitest-midscene-e2e
npx skills add https://github.com/web-infra-dev/midscene-skills --skill vitest-midscene-e2e- Node.js and npm/yarn installed
- Vitest configured in your project (or use the boilerplate scaffold)
- For Web tests: Playwright Chromium
- For Android tests: ADB and scrcpy installed and configured
- For iOS tests: WebDriverAgent (WDA) installed and configured
- `.env` file with required configuration (template provided by boilerplate)
How to use vitest-midscene-e2e
- 1.Run `bash scripts/clone-boilerplate.sh` to download the canonical boilerplate project structure and reference configs
- 2.Review the Midscene Agent API section in the skill documentation, especially the mandatory rule to use `aiAct` for all user-described UI actions
- 3.Create or update test files in the `e2e/` directory using the boilerplate's patterns as reference, with platform-specific context classes in `src/context/`
- 4.Write test steps using `aiAct(taskPrompt)` to describe UI interactions in natural language—do not decompose into fine-grained APIs like `aiTap` or `aiInput`
- 5.Run tests with `npm run test:e2e` (or equivalent) and check `troubleshooting.md` if tests fail
Use cases
- Write cross-platform E2E tests for a web app and its mobile versions without maintaining separate selector-based test suites
- Convert an existing Vitest project to use AI-powered UI interactions for more maintainable tests
- Debug failing tests by using natural-language descriptions of expected UI behavior
- Test workflows that span multiple pages or screens with phase-split `aiAct` calls for clarity
- Automate file uploads and complex multi-step user journeys described in plain language
- QA engineers and test automation specialists building E2E test suites
- Full-stack developers adding test coverage to web and mobile applications
- Teams maintaining tests across Web, Android, and iOS platforms simultaneously
- Projects seeking to reduce test maintenance overhead from selector-based testing
vitest-midscene-e2e FAQ
Always use `aiAct` when the user describes a UI action or state confirmation in natural language. Pass the intent directly to `aiAct` and let Midscene's AI handle planning and execution. Do not manually decompose user instructions into fine-grained APIs.
Split the task into separate `aiAct` calls, one per logical phase or page boundary. Each phase should be self-contained, and all phases combined must match the user's original intent.
Yes. The boilerplate includes platform-specific context classes (`WebTest`, `AndroidTest`, `IOSTest`) that share the same AI methods. Include only the platform files you need when setting up your project.
Use `aiActionContext` to define the AI's role and expertise (e.g., 'You are a Web UI testing expert'). Do not use it for specific actions or page descriptions—those belong in individual `aiAct()` calls.
When an `aiAct` prompt asks Midscene to upload files, pass `fileChooserAllowedDir` with the smallest directory containing your test fixtures, and refer to files relative to it in the prompt.
Full instructions (SKILL.md)
Source of truth, from web-infra-dev/midscene-skills.
name: vitest-midscene-e2e description: "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, 写测试, 加测试, 创建测试, 更新测试, 修复测试, 调试测试, 运行测试, 新建工程, 转化工程." user-invocable: true argument-hint: "[create|update|run|init] <feature-name>"
Vitest Midscene E2E
Modules
| 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:
- Web —
WebTest(Playwright Chromium):ctx.agent+ctx.page - Android —
AndroidTest(ADB + scrcpy):ctx.agentonly - iOS —
IOSTest(WebDriverAgent):ctx.agentonly
Workflow
Step 1: Clone boilerplate & ensure project ready
bash scripts/clone-boilerplate.sh
The 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.
Step 2: Read the Midscene Agent API section below before writing tests
It contains mandatory rules for using aiAct — the primary API for all UI operations. Do NOT skip this step.
Step 3: Create, update, or run tests
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.
Midscene Agent API
ctx.agent is a platform-specific agent instance. All methods return Promises.
- Web:
PlaywrightAgentfrom@midscene/web/playwright - Android:
AndroidAgentfrom@midscene/android - iOS:
IOSAgentfrom@midscene/ios
All three agents share the same AI methods below.
Mandatory Rule: Use aiAct for User-Described Steps
When 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.
// User says: "type iPhone in the search box and click search"
// WRONG — manually decomposing into fine-grained APIs
await ctx.agent.aiInput('search box', { value: 'iPhone' });
await ctx.agent.aiTap('search button');
// CORRECT — pass intent directly to aiAct
await ctx.agent.aiAct('type "iPhone" in the search box, then click the search button');
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(taskPrompt, opt?) — Primary API
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.
// UI operations
await ctx.agent.aiAct('type "iPhone" in the search box, then click the search button');
await ctx.agent.aiAct('hover over the user avatar in the top right');
// State confirmations / assertions — also use aiAct
await ctx.agent.aiAct('verify the page shows "Login successful"');
await ctx.agent.aiAct('verify the error message is visible');
Prompt-driven File Uploads (Web only)
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.
await ctx.agent.aiAct(
'click the upload button and upload avatar.png',
{ fileChooserAllowedDir: './fixtures' },
);
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.
// Incorrect — prompt spans multiple pages and too many steps, AI may lose context mid-way
await ctx.agent.aiAct('click the settings button in the top nav, go to settings page, find personal info and click into it, change email to "test@example.com", change phone to "13800000000", click save, wait for success');
// Correct — split by page/stage boundary, each phase stays within one logical context
await ctx.agent.aiAct('click the settings button in the top nav, go to settings page, find personal info and click into it');
await ctx.agent.aiAct('change email to "test@example.com", change phone to "13800000000", click save');
await ctx.agent.aiAct('verify the save success message appears');
aiActionis deprecated. UseaiActoraiinstead.
Common Mistakes
- Vague locators —
'button'is ambiguous; use'the blue "Submit" button at the top of the page' - Deprecated
aiAction— useaiActinstead - Ambiguous multi-element targets — specify row/position:
'the delete button in the first product row'
Agent Configuration — aiActionContext
aiActionContext is a system prompt string appended to all AI actions performed by the agent. Use it to define the AI's role and expertise.
// Set via agentOptions in setup()
const ctx = WebTest.setup('https://example.com', {
agentOptions: {
aiActionContext: 'You are a Web UI testing expert.',
},
});
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 inaiAct(), notaiActionContext'The page is in Chinese.'— this is page description, not a system prompt
How to Look Up More
- In
node_modules/@midscene/web,node_modules/@midscene/android, andnode_modules/@midscene/ios, find the type definitions for the agent classes - If types are not enough, follow the source references in the
.d.tsfiles to read the implementation code innode_modules - Download https://midscenejs.com/llms.txt, then use
grepto search for the API or concept you need (the file is large, do not read it in full)
Related skills
More from web-infra-dev/midscene-skills and the wider catalog.

android-device-automation
Vision-driven Android device automation using natural language commands via ADB and Midscene.

browser-automation
Vision-driven browser automation from screenshots — no DOM needed, works with Puppeteer, CDP, or Bridge mode.

chrome-bridge-automation
|

computer-automation
Vision-driven desktop automation for native apps and remote Windows via RDP using natural language.

webup-statusline
Generate and install a custom Claude Code status line with selectable columns and color themes.

wechatpay-basic-payment
微信支付基础支付解决方案,涵盖支付、退款账单、分账、商户进件、开户意愿确认,提供选型/代码示例/业务速查/质量评估/排障五大能力。Use when user mentions "JSAPI支付", "APP支付", "H5支付", "Native支付", "小程序支付", "付款码支付", "合单支付", "特约商户进件", "开户意愿确认", or asks to "推荐支付方式", "要支付接口代码示例", "排查支付或退款问题".