openApp, runTool, listTools, parkedOn, confirm
Drive a page's WebMCP tools from Playwright, the way an agent would.
Playwright helpers that drive the page’s tools through window.agent, which the devtools install in development builds: run e2e against vite dev or a build with the devtools on. Use test.use({ reducedMotion: "reduce" }) so the cursor snaps.
Import
import { confirm, listTools, openApp, parkedOn, runTool } from "@webmcp-agents/testing/playwright";
Example
import { expect, test } from "@playwright/test";
import {
confirm,
listTools,
openApp,
parkedOn,
runTool,
} from "@webmcp-agents/testing/playwright";
test.use({ reducedMotion: "reduce" });
test("books a flight after the person confirms", async ({ page }) => {
await openApp(page, "/");
expect(await listTools(page)).toContain("search_flights");
const query = { from: "CAI", to: "LHR", date: "2026-12-20" };
await runTool(page, "search_flights", query);
await expect(page).toHaveURL(/\/results\?/);
const booking = runTool(page, "book_flight", { id: "SK-204" });
const button = page.getByRole("button", { name: "Confirm booking" });
await parkedOn(page, button);
await confirm(page, button);
expect(await booking).toMatch(/booked/i);
});
Options
openApp(page, path, options?).
| Name | Type | Default | Description |
|---|---|---|---|
timeout |
number |
Playwright’s expect timeout | How long openApp waits for window.agent and the tools. |
Returns
openApp: once tools are registered. runTool: the tool’s text answer (Error [code]: … for a failure), undefined after a navigation. listTools: the names, sorted. parkedOn: once the cursor is parked on the control. confirm: parkedOn, then a real click.
Notes
The entry needs @playwright/test: importing it without it fails with a sentence naming it.