vitest-midscene-e2e by web-infra-dev/midscene-skills
npx skills add https://github.com/web-infra-dev/midscene-skills --skill vitest-midscene-e2e| 模块 | 角色 |
|---|---|
| Vitest | TypeScript 测试框架。提供 describe/it/expect/hooks 用于测试组织、断言和生命周期管理。 |
| Midscene | AI 驱动的 UI 自动化。通过自然语言与 UI 元素交互 —— 无需脆弱的定位器。核心 API:aiAct。 |
支持的平台:
WebTest (Playwright Chromium): ctx.agent + 广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
ctx.pageAndroidTest (ADB + scrcpy): ctx.agent onlyIOSTest (WebDriverAgent): ctx.agent onlybash scripts/clone-boilerplate.sh
位于 ~/.midscene/boilerplate/vitest-all-platforms-demo/ 的样板项目是项目结构、配置、平台上下文类和测试约定的规范参考。将当前项目与之比较。如果有任何缺失,询问用户需要哪个平台(Web / Android / iOS),然后使用样板项目作为目标状态来填充缺失的内容。只包含所请求平台的文件。不要覆盖现有的配置或文件。如果不存在,从样板项目复制 .env.example 为 .env,并提示用户填写环境变量。
它包含了使用 aiAct 的强制性规则 —— 这是所有 UI 操作的主要 API。不要跳过此步骤。
使用样板项目的 e2e/ 目录和 src/context/ 作为模式和约定的参考。在运行测试之前,确保依赖已安装且 .env 已配置。调试失败时,请查阅 troubleshooting.md。
ctx.agent 是一个特定于平台的代理实例。所有方法都返回 Promise。
PlaywrightAgent from @midscene/web/playwrightAndroidAgent from @midscene/androidIOSAgent from @midscene/ios所有三个代理共享以下相同的 AI 方法。
aiAct当用户用自然语言描述一个 UI 操作或状态确认时,你必须使用
aiAct来实现它。 不要将用户指令分解为aiTap/aiInput/aiAssert或其他细粒度 API。将用户的意图直接传递给aiAct,让 Midscene 的 AI 处理规划和执行。
// 用户说:"在搜索框中输入 iPhone 并点击搜索"
// 错误 — 手动分解为细粒度 API
await ctx.agent.aiInput('搜索框', { value: 'iPhone' });
await ctx.agent.aiTap('搜索按钮');
// 正确 — 将意图直接传递给 aiAct
await ctx.agent.aiAct('在搜索框中输入 "iPhone",然后点击搜索按钮');
断言、数据提取和等待也应该通过 aiAct 完成 —— 它处理所有这些。不要单独使用 aiAssert、aiQuery、aiWaitFor、aiTap 或 aiInput。
aiAct 是所有 UI 操作和状态确认的主要 API。 它接受自然语言指令,并自主规划和执行多步骤交互。
// UI 操作
await ctx.agent.aiAct('在搜索框中输入 "iPhone",然后点击搜索按钮');
await ctx.agent.aiAct('将鼠标悬停在右上角的用户头像上');
// 状态确认 / 断言 — 也使用 aiAct
await ctx.agent.aiAct('验证页面显示 "登录成功"');
await ctx.agent.aiAct('验证错误消息可见');
阶段拆分: 如果任务提示过长或涵盖多个不同的阶段,将其拆分为单独的 aiAct 调用 —— 每个阶段一个。每个阶段应该是一个自包含的逻辑步骤,所有阶段组合起来必须匹配用户的原始意图。
// 不正确 — 提示跨越多个页面和太多步骤,AI 可能在过程中丢失上下文
await ctx.agent.aiAct('点击顶部导航栏中的设置按钮,进入设置页面,找到个人信息并点击进入,将邮箱改为 "test@example.com",将电话改为 "13800000000",点击保存,等待成功');
// 正确 — 按页面/阶段边界拆分,每个阶段保持在一个逻辑上下文中
await ctx.agent.aiAct('点击顶部导航栏中的设置按钮,进入设置页面,找到个人信息并点击进入');
await ctx.agent.aiAct('将邮箱改为 "test@example.com",将电话改为 "13800000000",点击保存');
await ctx.agent.aiAct('验证保存成功消息出现');
aiAction已弃用。请使用aiAct或ai。
'button' 是模糊的;使用 '页面顶部的蓝色"提交"按钮'aiAction — 改用 aiAct'第一个产品行中的删除按钮'aiActionContextaiActionContext 是一个系统提示字符串,会附加到代理执行的所有 AI 操作上。用它来定义 AI 的角色和专业领域。
// 通过 setup() 中的 agentOptions 设置
const ctx = WebTest.setup('https://example.com', {
agentOptions: {
aiActionContext: '你是一名 Web UI 测试专家。',
},
});
好的例子:
'你是一名 Web UI 测试专家。''你是一名熟悉中文 UI 的 Android 应用测试专家。'坏的例子:
'点击登录按钮。' — 具体操作属于 aiAct(),而不是 aiActionContext'页面是中文的。' — 这是页面描述,不是系统提示node_modules/@midscene/web、node_modules/@midscene/android 和 node_modules/@midscene/ios 中,查找代理类的类型定义.d.ts 文件中的源代码引用,在 node_modules 中阅读实现代码grep 搜索你需要的 API 或概念(文件很大,不要全文阅读)每周安装量
109
仓库
GitHub 星标数
137
首次出现
6 天前
安全审计
安装于
openclaw73
codex51
opencode50
cline49
cursor49
kimi-cli48
| 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 onlybash 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.
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.
// 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 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');
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.
'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.
// 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 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)Weekly Installs
109
Repository
GitHub Stars
137
First Seen
6 days ago
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
openclaw73
codex51
opencode50
cline49
cursor49
kimi-cli48
AI Elements:基于shadcn/ui的AI原生应用组件库,快速构建对话界面
69,600 周安装