Skip to content
WebMCP Agents
Esc
↑↓navigate↵open⌘Jpreview
On this page

End to end

Drive the running app's tools from Playwright through window.agent: wait for the tools, run one, assert a parked confirmation, click it.

The other pages test pieces. An end-to-end test runs the app as people use it: the router, the real components, the real styles. With Playwright, you call the app’s tools the same way the devtools do, through window.agent, and check the page.

A complete 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);
});

openApp opens the page and waits until window.agent and the tools are there. runTool calls a tool in the page and resolves with the text the agent would read. parkedOn(page, button) waits until the cursor waits on that button; confirm clicks it as the person.

What it needs

  • window.agent exists where the devtools are installed: development builds (vite dev, next dev), or a build with the devtools turned on. Point Playwright’s webServer at one of those.
  • reducedMotion: "reduce" makes the cursor snap, so tests do not wait for it to glide.
  • This example is type-checked here but not run: it needs a running app. The example apps in this repository run the same calls in their own end-to-end tests.

See also

Was this page helpful?