Back to MCP directory
verified_userVerifieddnsLocal runtime

Playwright Browser Automation

Playwright MCP是一个基于Playwright的浏览器自动化服务器,通过结构化数据而非像素输入实现LLM与网页的交互。

article

README

🚀 Playwright

Playwright 是一款强大的自动化测试工具,可帮助开发者高效地对网页应用进行测试,支持多种浏览器,能有效提升测试效率和质量。

🚀 快速开始

使用 Playwright 进行测试,可按以下步骤操作:

  1. 安装 Node.js:确保系统中已安装 Node.js 和 npm。
  2. 安装 Playwright
    npm install -g playwright
    
  3. 初始化项目
    mkdir my-playwright-project
    cd my-playwright-project
    playwright init --ts
    
  4. 选择浏览器:根据提示选择需要的浏览器(如 chromium、firefox 或 webkit)。
  5. 编写测试脚本:创建 playwright.config.ts 文件并配置测试选项。
  6. 运行测试
    npm run test
    

💻 使用示例

基础用法

import { test, expect } from '@playwright/test';

test('搜索关键字', async ({ page }) => {
  // 打开浏览器
  await page.goto('https://www.baidu.com');
  // 输入搜索关键字
  await page.type('.kw', 'Playwright');
  // 点击搜索按钮
  await page.click('#su');
});

高级用法

// playwright.config.ts 配置文件示例
module.exports = {
  testDir: './tests',
  forbidOnly: !!process.env.CI,
  requireOrder: ['playwright/test/fetch'],
  workers: process.env.CI ? 1 : undefined,
  reporter: 'html',
  use: {
    baseURL: 'http://localhost:3000',
    browser: 'chromium',
    chromium: {
      // 设置为无头模式
      headless: true,
      // 设置 viewport 大小
      viewport: { width: 1920, height: 1080 }
    },
    // 配置 firefox 或者 webkit 的参数
  },
};
help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client