mp_runScenario
Execute a series of mini-program actions (navigate, tap, input) and assertions, then summarize each step's pass/fail. Designed for automated regression testing of short user flows.
Instructions
按顺序执行一组小程序调试/回归步骤,一次调用跑完并汇总每步 pass/fail。用于把一条短链路脚本化复跑(导航→操作→断言);只做单次交互探查请用单个 page_*/element_* 工具。要把结果整理成 markdown 复核产物时改用 mp_generateScenarioReport(参数相同)。
steps[] 每项必带 type,最多 25 步,共 12 种(分动作类与断言类):
● 动作类(不返回 pass,只在抛错时算失败):
navigate {path?, query?, transition?=navigateTo|redirectTo|reLaunch|switchTab|navigateBack, waitMs?} — 只有 navigateBack 可省略 path;waitMs 是 dumb sleep,时序敏感场景宁可用 waitRoute 步或拆出来用 mp_pollUntil
tap {selector, innerSelector?, waitMs?}
input {selector, innerSelector?, value(string|number)}
snapshot {selectors?[], dataPaths?[], withData?=false, withElements?=true, withWxml?=false, limit?=10, maxBytes?=50000} — 每个 selector 受 limit 限制,所有 selector 合计最多汇总 100 个元素摘要;超 maxBytes 会截断并返回 note;比独立 page_snapshot 弱
getLogs {clear?, contains?, logType?, since?, limit?=100}
screenshot {path?, timeoutMs?=30000} — 不传 path 时不回传 base64(只给 note),要图请单独调 mp_screenshot 或传 path 存文件;连续 2 次截图通道失败后会短路 ● 断言类(决定 scenario 整体 ok/pass):
waitRoute {path, timeout?=5000, retryInterval?=200} — 轮询直到 route 命中,返回 matched
expectRoute {path} — 即时断言当前 route
expectVisible {selector} — 命中 ≥1 个即过
expectText {selector, expected, mode?=equals|includes}
expectCount {selector, expected(整数)}
expectData {path, expected} — 必须显式给 expected;path 未解析到值且 expected 省略时直接判失败(避免 undefined===undefined 静默判过)
⚠️ selector 用 page.$ / page.$$,不穿透自定义组件内部;组件内元素用 innerSelector(在父元素内再查),取第 N 个匹配用 selector[index=N] 语法。
⚠️ 想要真正验证就必须放至少一个断言步:纯动作步全部不抛错也只代表跑通了,ok=true 不等于断言通过。
stopOnFailure 默认 true:遇到首个失败步即停,后续步不执行;设 false 跑完所有步再汇总。scenarioTimeoutMs 控制整体预算,默认 120000ms、最大 600000ms。maxBytes 控制聚合结果大小,默认 500000B。
建议每个 scenario 保持短(≤ ~10 步):snapshot/screenshot 在长链路后段更易超时/抖动 — 拆成多个短 scenario 分段跑。
返回 {ok, totalSteps, executedSteps, passedSteps, failedSteps, results[]},每个 result = {index, type, pass, step, result 或 error}。
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| steps | Yes | ||
| maxBytes | No | ||
| connection | No | 可选连接覆盖(不传则用默认会话)。可用字段:mode(launch|connect)、cliPath、projectPath、wsEndpoint、timeout、port(【自动化端口】→ cli auto --auto-port,默认 9420;不是 IDE HTTP 服务端口,别把 IDE 服务端口传进来)、account、ticket、trustProject、args、cwd、autoClose、autoLaunch、launchTimeout、connectTimeout。 | |
| stopOnFailure | No | ||
| scenarioTimeoutMs | No |