Neler yeni

Playwright 1.64 WebMCP Testing: Inspect and Call Page Tools

kasenur

kasenur 

GlomaxGPT
Administrator
Üye
Puan 28,728
Çözümler 0
Table of ContentsHow to Test WebMCP Tools with PlaywrightTable of ContentsWhy WebMCP Testing MattersPrerequisites and Tech StackProject Setup: Scaffold and ConfigureCreating a Test Page That Exposes WebMCP ToolsA Note on File Paths in TestsDiscovering Page-Registered Tools with page.webmcp.tools()Executing Tool Calls with page.webmcp.callTool()Example-Based API Lookup Table and CLI ReferencePutting It All Together: Full Runnable Test FileTips, Gotchas, and Best PracticesCommon PitfallsNext StepsTable of ContentsHow to Test WebMCP Tools with PlaywrightTable of ContentsWhy WebMCP Testing MattersPrerequisites and Tech StackProject Setup: Scaffold and ConfigureCreating a Test Page That Exposes WebMCP ToolsA Note on File Paths in TestsDiscovering Page-Registered Tools with page.webmcp.tools()Executing Tool Calls with page.webmcp.callTool()Example-Based API Lookup Table and CLI ReferencePutting It All Together: Full Runnable Test FileTips, Gotchas, and Best PracticesCommon PitfallsNext StepsPlaywright 1.64 WebMCP Testing: How to Inspect and Call Page ToolsSitePoint TeamPublished inProgramming·Web·October 8, 2026The AI briefing for DevelopersStay up to date with AI tools, model releases, and developer workflows that matter.Weekly. Free. One click to leave.Share this articleSitePoint PremiumStay Relevant and Grow Your Career in TechPremium ResultsPublish articles on SitePointDaily curated jobsLearning PathsDiscounts to dev toolsStart Free Trial7 Day Free Trial. Cancel Anytime.

WebMCP is a browser-level protocol that allows web pages to register callable "tools" for AI agents, automation consumers, and other programmatic clients to discover and invoke. This article walks through building a small but complete Playwright test project from scratch.

How to Test WebMCP Tools with Playwright

Scaffold a new project with npm init, install @playwright/[email protected], and download the bundled Chromium binary.
Configure playwright.config.ts to pass the --enable-features=WebMCP launch argument to Chromium.
Create an HTML fixture page that registers WebMCP tools using document.modelContext.registerTool().
Build a shared helper module to generate cross-platform file URLs for the fixture page.
Discover registered tools by calling page.webmcp.tools() and asserting the returned descriptors.
Execute tool calls with page.webmcp.callTool(name, params?) and validate the returned results.
Assert error handling by invoking non-existent tools and matching specific error messages.
Integrate the test suite into CI using a Playwright Docker base image with the WebMCP flag enabled.

Why WebMCP Testing Matters
Prerequisites and Tech Stack
Project Setup: Scaffold and Configure
Creating a Test Page That Exposes WebMCP Tools
A Note on File Paths in Tests
Discovering Page-Registered Tools with page.webmcp.tools()
Executing Tool Calls with page.webmcp.callTool()
Example-Based API Lookup Table and CLI Reference
Putting It All Together: Full Runnable Test File
Tips, Gotchas, and Best Practices
Common Pitfalls
Next Steps

Experimental feature: page.webmcp shipped in Playwright 1.64 (see the release notes) and drives Chrome's experimental WebMCP browser API. The browser API can change between Chromium releases, so pin your Playwright version and re-run your tests when you upgrade.

WebMCP is a browser-level protocol that allows web pages to register callable "tools" for AI agents, automation consumers, and other programmatic clients to discover and invoke. Think of it as a structured contract: a page declares what actions it can perform, along with input schemas, and external callers execute those actions through a standardized interface.

This sits at the intersection of the proliferation of LLM-driven browser agents and traditional web automation, giving pages a way to expose capabilities beyond the DOM. This article walks through building a small but complete Playwright test project from scratch. It covers launching Chromium with a WebMCP feature flag, creating a fixture page that registers tools, discovering those tools programmatically, calling them with and without parameters, and asserting results.

Node.js 18 or later: verify with node --version
npm 8 or later - verify with npm --version
Playwright Test - pinned to a specific version (see setup below). You must confirm that your installed version ships with page.webmcp support by checking the Playwright changelog.
Chromium (bundled with Playwright; no separate install needed)
TypeScript - a tsconfig.json is required (provided below)

Comfortable writing Playwright tests in TypeScript
Familiar with npx playwright test and the structure of playwright.config.ts
Basic understanding of JSON Schema concepts (helpful but not strictly required)

Project Setup: Scaffold and Configure

The following commands create a new project directory, initialize a package.json, install Playwright as a dev dependency with a pinned version, and download the bundled Chromium binary.
 
Uzun zamandır bu konuyu araştırıyordum, sonunda buldum.
 
Güzel bir özet olmuş, devamını da bekliyoruz.
 
Forum bu tür içeriklerle daha değerli oluyor.
 
Bu konuyu araştırıyordum tam zamanında geldi, bookmarkledim.
 
Teşekkürler, arkadaşlarıma da önereceğim.
 

Tema özelleştirme sistemi

Bu menüden forum temasının bazı alanlarını kendinize özel olarak düzenleye bilirsiniz

Geri
Sponsorlu içerik Reklam 1 / 3
Bexgram reklam görseli
Bexgram Sosyal medya ve sohbet
Siteye git