Skip to main content
Glama

如何使用 playwright-mcp?

npm 版本 文档

介绍

playwright-mcp(模型上下文协议)是一款强大的工具,它弥合了 AI 助手和浏览器自动化之间的差距。它使 AI 模型能够与 Web 浏览器交互、检查 DOM 元素、记录用户交互,并生成更高精度的 Playwright 测试脚本。本指南将指导您如何有效地设置和使用 playwright-mcp。

Related MCP server: browser-devtools-mcp

工具

浏览器界面中可用的工具:

浏览器工具箱

  1. 选择 DOM (🎯):点击即可从页面中选择并捕获 HTML 元素。使用它来记录测试用例的选择器。

  2. 选择图像 (📸):截取特定元素的屏幕截图。适用于视觉测试或文档撰写。

  3. 记录交互 (📋):记录浏览器交互,例如点击、输入和导航。这些交互会自动生成选择器,并可以作为上下文传递给 Claude 或 Cursor 等 MCP 客户端,以帮助编写测试用例。

MCP 命令

  1. init-browser :初始化剧作家浏览器。

  2. get-context :获取网站上下文,用于编写测试用例

  3. execute-code :针对当前页面执行自定义 Playwright JS 代码

  4. get-screenshot :获取当前页面的屏幕截图

  5. get-full-dom :获取当前页面的完整 DOM。(建议使用get-context代替)

了解更多

想深入了解?查看完整文档:

📖查看文档

Available Tools

5 tools
execute-codeA

Execute custom Playwright JS code against the current page

Inputs: code (required).

get-contextB

Get the website context which would be used to write the testcase

Inputs: no named parameters.

get-full-domA

Get the full DOM of the current page. (Deprecated, use get-context instead)

Inputs: no named parameters.

get-screenshotB

Get a screenshot of the current page

Inputs: no named parameters.

init-browserC

Initialize a browser with a URL

Inputs: url (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.4/5.0

    Scored across 5 tools

    Disambiguation3/5

    Most tools have distinct purposes, but get-context and get-full-dom overlap significantly, with the latter deprecated in favor of the former. This creates ambiguity about which to use for DOM-related tasks, though the deprecation note helps clarify.

    Naming Consistency4/5

    The tools follow a consistent verb_noun pattern with hyphens, such as execute-code and get-screenshot. The only minor deviation is init-browser, which uses 'init' instead of a more standard verb like 'initialize', but overall the naming is predictable and readable.

    Tool Count4/5

    With 5 tools, the count is reasonable for a Playwright automation server, covering core operations like initialization, execution, and inspection. It might benefit from additional tools for actions like navigation or element interaction, but it's well-scoped for basic functionality.

    Completeness3/5

    The tools cover initialization, code execution, and page inspection, but there are notable gaps for common Playwright workflows, such as navigation (e.g., go-to-url), element interaction (e.g., click, fill), or test assertion. This limits the server's ability to handle full automation tasks without workarounds.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers