Skip to content

Add example: self-healing Playwright tests with multi-model fallback#93

Open
Desperado wants to merge 3 commits into
e2b-dev:mainfrom
Desperado:add-self-healing-playwright-tests
Open

Add example: self-healing Playwright tests with multi-model fallback#93
Desperado wants to merge 3 commits into
e2b-dev:mainfrom
Desperado:add-self-healing-playwright-tests

Conversation

@Desperado

Copy link
Copy Markdown

Adds a new cookbook example demonstrating the self-healing test pattern on top of the playwright-chromium template.

What it shows

  • Generate a Playwright test from a natural-language spec via the Vercel AI SDK, with multi-model fallback (Claude → GPT → Gemini) so a single-provider outage doesn't stall the loop.
  • Run the test in a fresh playwright-chromium sandbox per attempt.
  • On failure, dump page.content() to the filesystem, read it back out, feed it into the next LLM call so the retry can anchor selectors on real DOM.

Structure

Three small modules (router.ts / runner.ts / healer.ts, ~250 lines). Four runnable examples: basic, self-healing, fallback, parallel suite.

Notes on playwright-chromium

The template ships playwright + browser binaries but not @playwright/test. The runner installs that in a user-writable work dir (since /app is root-owned) and points PLAYWRIGHT_BROWSERS_PATH at the template's pre-baked Chromium so the test runner doesn't re-download.

Verified end-to-end

  • npm install + npm run typecheck clean
  • npm run example:healing passes in 2 attempts (fail → snapshot feedback → pass)
  • Per attempt ~30–80 s wall clock; full healing demo ~2–4 min

Pattern inspired by the self-healing behaviour at qualitymax.io; code is standalone TypeScript.

Also adds a one-line bullet to the root README's "Example use cases" section.

Desperado and others added 2 commits April 24, 2026 21:31
Adds a new cookbook example that demonstrates:

- Generating a Playwright test from a natural-language spec via the
  Vercel AI SDK, with multi-model fallback (Claude -> GPT -> Gemini)
  so a single-provider outage doesn't stall the loop.
- Running the generated test in the pre-baked `playwright-chromium`
  template (fresh sandbox per attempt).
- On failure: capturing the page HTML via fs.writeFileSync, reading
  it back out of the sandbox, and feeding it into the next LLM call
  so the retry gets real DOM to anchor selectors on.

Three small modules, ~250 lines total (router.ts / runner.ts /
healer.ts). Four runnable examples: basic, self-healing, fallback,
parallel suite.

Pattern inspired by the self-healing behaviour at qualitymax.io;
code is standalone TypeScript.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Three updates rolled in from production use at qualitymax.io:

1. Inject test.afterEach capture hook server-side with sentinel-bracketed
   strip-and-reattach instead of trusting the LLM to write the snapshot.
   Closes three silent failure modes -- LLM omits the hook on heal,
   writes to root-owned /app/ (EACCES), or duplicates `import fs`
   producing a SyntaxError that fails every retry before the test runs.
   Also fixes a path bug: the prompt told the LLM to write to
   /app/failure.html but the runner read /home/user/work/failure.html,
   so the snapshot was never actually loaded.

2. Classify failures (strict_mode_violation / locator_not_found /
   timeout / assertion_failed / unknown) and only inject a strict-mode
   hint on the matching bucket. Without targeted guidance, the healer
   re-emits equivalent fragile locators and burns the heal budget on
   the same failure. The strict-mode hint points at three concrete fix
   patterns instead.

3. Sentinel-based progress (QMAX_PHASE:* markers) parsed from streaming
   onStdout/onStderr so UI consumers see real-time progress instead of
   an opaque "running...".

README updated with a "Battle-tested patterns" section explaining each.
typecheck clean.
@cla-bot

cla-bot Bot commented May 13, 2026

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement, and we don't have @Desperado on file. You can sign our CLA at https://e2b.dev/docs/cla . Once you've signed, post a comment here that says '@cla-bot check'

@Desperado

Copy link
Copy Markdown
Author

FYI — opened a companion PR #95 adding a separate example for the live noVNC browser feed pattern (referenced from this example's new "Battle-tested patterns" section). They're independent — happy to land them in either order.

@Desperado

Copy link
Copy Markdown
Author

@cla-bot check

@cla-bot cla-bot Bot added the cla-signed label May 13, 2026
@cla-bot

cla-bot Bot commented May 13, 2026

Copy link
Copy Markdown

The cla-bot has been summoned, and re-checked this pull request!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant