vitest-midscene-e2e
web-infra-dev/midscene-skills
VitestにMidsceneを統合し、Web(Playwright)、Android(ADB)、iOS(WDA)にわたるAIを活用したUIテストを実現します。新規プロジェクトのスケルトン生成、既存プロジェクトの変換、および自然言語によるUI操作を用いたE2Eテストの作成・更新・デバッグ・実行が可能です。 トリガー:テストの記述、テストの追加、テストの作成、テストの更新、テストの修正、テストのデバッグ、テストの実行、E2Eテスト、Midsceneテスト、新規プロジェクト、プロジェクトの変換、プロジェクトの初期化、テストの記述、 テストの追加、テストの作成、テストの更新、テストの修正、テストのデバッグ、テストの実行、プロジェクトの作成、プロジェクトの変換。
...すべて拡張します概要vitest-midscene-e2e
vitest-midscene-e2e は、Midsceneを活用してVitestテストフレームワークを強化し、Web(Playwright Chromium)、Android(ADBおよびscrcpy)、iOS(WebDriverAgent)にわたる、AIを活用した自然言語によるエンドツーエンドのUIテストを構築します。 これにより、セレクタベースのE2Eテストが抱える脆弱性の問題を解決します。ユーザーフローを不安定なタップや入力操作に分解する代わりに、テスターは平易な言語で意図をMidsceneのエージェントに伝達し、エージェントがインタラクションを計画・実行します。 このスキルは、新しいテストプロジェクトの骨組みを作成したり、既存のプロジェクトを変換したり、テストの作成・更新・デバッグ・実行を行ったりすることができ、トリガーフレーズは英語と中国語のバイリンガルに対応しています。
ワークフローは、バンドルされたスクリプトを介して標準的なボイラープレートをクローンすることから始まります。次に、現在のプロジェクトをそれと比較し、既存の設定を上書きすることなく、ユーザーが必要とするプラットフォームについて不足している部分のみを補完し、.env.example を .env にコピーして、ユーザーが値を入力できるようにします。 その中心となるルールは、ユーザーが記述した UI ステップは、きめ細かな aiTap/aiInput/aiAssert 呼び出しではなく、主要な aiAct API を使用して実装する必要があるという点です。これにより、AI が計画、アサーション、データ抽出、および待機を処理できるようになります。 また、同じAIメソッドを共有するプラットフォーム固有のエージェントクラス、ページやステージの境界による長いプロンプトのフェーズ分割、fileChooserAllowedDirに制限されたプロンプト駆動型のファイルアップロード(プロジェクトのルートディレクトリやホームディレクトリの使用を明示的に推奨しない)、 テスターの専門知識を設定するための aiActionContext システムプロンプトオプション、避けるべき一般的なロケーターのミス、および失敗時のトラブルシューティングリファレンスについても記載されています。
対象ユーザーは、Web、Android、iOS上で堅牢かつ自然な言語による自動化を求める、クロスプラットフォームのE2Eテストを作成する開発者やQAエンジニアです。 実行には、設定済みの環境変数(Midscene用のAIモデル認証情報を含む)およびPlaywright、ADB、WebDriverAgentなどのプラットフォームツールチェーンが必要です。このスキルはクローンスクリプトを実行してテストを駆動しますが、その適用範囲は正当なテストワークフローに限定されており、広範なパスを公開するのではなく、ファイルアップロードディレクトリを絞り込むよう推奨しています。
よくある質問
どのプラットフォームに対応していますか?
WebはPlaywright Chromium経由、AndroidはADBおよびscrcpy経由、iOSはWebDriverAgent経由で対応しています。Webではctx.agentとctx.pageの両方が利用可能ですが、AndroidとiOSではctx.agentのみが利用可能です。これら3つのエージェントはすべて、同じAIメソッドを共有しています。
テストステップはどのように記述しますか?
ユーザーの意図を、aiTap、aiInput、aiAssertに分解するのではなく、主要なAPIであるaiActに自然言語として渡してください。aiActはアサーション、データ抽出、待機も処理します。非推奨となったaiActionはaiActに置き換える必要があります。
どのようなセットアップが必要ですか?
提供されたスクリプトを使用してボイラープレートをクローンし、依存関係をインストールし、Midscene用のAIモデル認証情報を含む必要な変数を指定して.env(.env.exampleからコピー)を設定してください。また、関連するプラットフォームのツールチェーン(Playwright、ADB/scrcpy、またはWebDriverAgent)も必要です。
ファイルのアップロードはどのように安全に処理されますか?
aiActプロンプトでファイルをアップロードする際は、そのテストのフィクスチャを含む最小のディレクトリに設定した`fileChooserAllowedDir`を渡します。スキルでは、プロジェクトのルートディレクトリやホームディレクトリを使用しないよう明示的に指定されています。
プロンプトが複数のステップにまたがる場合はどうすればよいですか?
AIがフローの途中でコンテキストを失わないよう、ページやステージの境界で個別のaiAct呼び出しに分割してください。その際、すべてのフェーズを合わせると元の意図と一致するようにしてください。トラブルシューティングのリファレンスには、失敗時のデバッグ方法が記載されています。
すべてのファイル
3ファイルSKILL.md7.0KB表示scripts/clone-boilerplate.sh1.2KB表示references/troubleshooting.md2.2 KB表示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 APIsawait ctx.agent.aiInput('search box', { value: 'iPhone' });await ctx.agent.aiTap('search button');// CORRECT — pass intent directly to aiActawait 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 operationsawait 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 aiActawait 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-wayawait 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 "[email protected]", change phone to "13800000000", click save, wait for success');// Correct — split by page/stage boundary, each phase stays within one logical contextawait 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 "[email protected]", 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)
すべてのファイル
3件のファイルvitest-midscene-e2eをインストール
スキルファイルをダウンロードし、.claude/skills/ ディレクトリに解凍してください。
ZIPをダウンロードリポジトリをクローンし、スキルファイルをプロジェクトにコピーしてください。
git clone https://github.com/web-infra-dev/midscene-skills/blob/main/skills/vitest-midscene-e2e/SKILL.md # Copy SKILL.md to your .claude/skills/ directory
コピー





家
