
Vitest Midscene E2e
Stabilize Vitest plus Midscene AI-driven E2E tests when timeouts, wrong elements, or flaky assertions block ship.
Overview
Vitest Midscene E2E is an agent skill for the Ship phase that troubleshoots AI-driven Vitest tests using wait-aware aiAct prompts and precise element descriptions.
Install
npx skills add https://github.com/web-infra-dev/midscene-skills --skill vitest-midscene-e2eWhat is this skill?
- Documents 180s default per-test timeout for slower AI-driven flows versus selector tests
- Teaches embedding wait-in-prompt in aiAct so assertions do not fire before UI settles
- Position, text, and row-context prompts to fix element-not-found and wrong-target clicks
- Covers headed-mode, network, and timeout failure modes tagged HIGH impact
- TypeScript examples for incorrect versus correct Midscene agent steps
- 180s default timeout per AI-driven test
- HIGH impact troubleshooting tags: debug, timeout, element-not-found, network, headed-mode
Adoption & trust: 1.2k installs on skills.sh; 240 GitHub stars; 2/3 security scanners passed (skills.sh audits).
What problem does it solve?
Your Midscene E2E tests fail on timeout or wrong elements because AI actions finish before the UI updates or your prompts are too vague.
Who is it for?
Indie teams already running Vitest with Midscene who need practical fixes for timeout and element-matching failures.
Skip if: Greenfield Midscene project setup with no tests yet, or teams that only use Playwright-style selectors without Midscene aiAct.
When should I use this skill?
Midscene Vitest E2E fails on timeout, premature assertion, element-not-found, or ambiguous aiAct targeting.
What do I get? / Deliverables
After applying the patterns, tests wait for real UI state and target the intended controls so Ship-phase E2E runs pass more reliably.
- Corrected aiAct prompt patterns
- Stable wait-before-assert test steps
Recommended Skills
Journey fit
Spans multiple journey phases - primary shelf plus alternate fits below.
Canonical shelf is Ship because the skill addresses running and debugging end-to-end tests before release. Testing subphase matches Vitest E2E workflows, assertion timing, and AI act prompt patterns.
Where it fits
Draft aiAct steps for a new checkout flow with embedded wait language before merging UI.
Unblock CI E2E failures caused by assertions running before async submission completes.
Tighten production regression tests after users report UI timing bugs caught only in AI E2E.
How it compares
Use alongside selector-based E2E docs when you need AI-act prompt discipline, not a replacement for Vitest config reference.
Common Questions / FAQ
Who is vitest-midscene-e2e for?
Solo and indie builders running Vitest with Midscene agent steps who hit timeouts, flaky assertions, or ambiguous element clicks during pre-release testing.
When should I use vitest-midscene-e2e?
Use in Ship testing when E2E fails early; also during Build frontend work while authoring new aiAct flows, and in Operate iterate when production regressions need the same prompt fixes.
Is vitest-midscene-e2e safe to install?
Review the Security Audits panel on this Prism page and inspect the skill source in your repo before granting browser or shell access to your agent.
SKILL.md
READMESKILL.md - Vitest Midscene E2e
# Troubleshooting ## Timeout / Assertion Too Early AI-driven tests are slower than selector-based tests. Default timeout is 180s per test. Most timeout and premature assertion failures are caused by not waiting for the page/app to be ready. Include waiting in the `aiAct` prompt itself, so Midscene waits for the page/app to be ready before asserting: ```typescript // Incorrect — assertion fires before page updates await ctx.agent.aiAct('click the submit button'); await ctx.agent.aiAct('verify the page shows "Submission successful"'); // Correct — include wait in the action prompt await ctx.agent.aiAct('click the submit button and wait until the submission completes'); await ctx.agent.aiAct('verify the page shows "Submission successful"'); ``` --- ## Element Not Found / Wrong Element Vague or ambiguous descriptions cause AI to match the wrong element or fail entirely. ```typescript // Incorrect — too vague, multiple buttons may exist await ctx.agent.aiAct('click the button'); await ctx.agent.aiAct('click the delete button'); // Correct — include position, context, or visual traits await ctx.agent.aiAct('click the blue "Submit" button at the top of the page'); await ctx.agent.aiAct('click the delete button in the first product row'); ``` Tips for precise descriptions: - Include **position**: top / bottom / first row / left side - Include **text content**: "Submit" / "Confirm" / "Delete" - Include **visual traits**: blue / large / with icon --- ## Device Connection **Android** — ensure a device is connected and ADB is configured: ```bash adb devices # Should list your device ``` If using a remote device, set `MIDSCENE_ADB_REMOTE_HOST` and `MIDSCENE_ADB_REMOTE_PORT` in `.env`. **iOS** — ensure WebDriverAgent is running on the target device/simulator: ```bash curl http://localhost:8100/status ``` Override the port via `IOSTest.setup(uri, { deviceOptions: { wdaPort: 8100 } })`. --- ## Debugging Tips - **Headed mode (Web)**: Use `WebTest.setup(url, { headless: false })` to see the browser during test execution - **Midscene report**: Check the generated report for screenshots and AI decision traces #!/bin/bash # Clone or update the Midscene boilerplate from the external repo. # First run: clones the repo. Subsequent runs: pulls once per day. # Usage: bash scripts/clone-boilerplate.sh BOILERPLATE_DIR="$HOME/.midscene/boilerplate" MARKER="$BOILERPLATE_DIR/.last_updated" # Fresh clone if directory doesn't exist if [ ! -d "$BOILERPLATE_DIR" ]; then git clone --depth 1 --branch main --filter=blob:none --sparse \ https://github.com/web-infra-dev/midscene-example.git "$BOILERPLATE_DIR" cd "$BOILERPLATE_DIR" || exit 1 git sparse-checkout set vitest-all-platforms-demo date +%s > "$MARKER" echo "Boilerplate cloned to $BOILERPLATE_DIR/vitest-all-platforms-demo/" exit 0 fi # Update if last pull was more than 1 day ago NOW=$(date +%s) LAST_UPDATED=$(cat "$MARKER" 2>/dev/null || echo 0) ELAPSED=$(( NOW - LAST_UPDATED )) ONE_DAY=86400 if [ "$ELAPSED" -ge "$ONE_DAY" ]; then echo "Boilerplate outdated (last update >1 day ago), pulling latest..." cd "$BOILERPLATE_DIR" && git fetch --depth 1 origin main 2>/dev/null && git pull --ff-only origin main 2>/dev/null || echo "Update failed, using existing boilerplate." date +%s > "$MARKER" else echo "Boilerplate is up to date." fi --- 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-