/ 目录 / 演练场 / playwright-skill
● 社区 lackeyjb ⚡ 即开即用

playwright-skill

作者 lackeyjb · lackeyjb/playwright-skill

Claude 可以按需编写和运行自定义 Playwright 脚本——有头浏览器、实际输出——无需记忆预置的测试库。

与其提供固定的辅助函数,这个技能教 Claude 为每个任务编写定制 Playwright 代码,并通过 run.js 执行。浏览器默认以有头模式运行,所以你能看到自动化过程。Playwright API 文档按需加载,这样 Claude 有上下文但不会溢出窗口。

为什么要用

核心特性

实时演示

实际使用效果

playwright-skill.replay ▶ 就绪
0/0

安装

选择你的客户端

~/Library/Application Support/Claude/claude_desktop_config.json  · Windows: %APPDATA%\Claude\claude_desktop_config.json
{
  "mcpServers": {
    "playwright-skill": {
      "command": "git",
      "args": [
        "clone",
        "https://github.com/lackeyjb/playwright-skill",
        "~/.claude/skills/playwright-skill"
      ],
      "_inferred": true
    }
  }
}

打开 Claude Desktop → Settings → Developer → Edit Config。保存后重启应用。

~/.cursor/mcp.json · .cursor/mcp.json
{
  "mcpServers": {
    "playwright-skill": {
      "command": "git",
      "args": [
        "clone",
        "https://github.com/lackeyjb/playwright-skill",
        "~/.claude/skills/playwright-skill"
      ],
      "_inferred": true
    }
  }
}

Cursor 使用与 Claude Desktop 相同的 mcpServers 格式。项目级配置优先于全局。

VS Code → Cline → MCP Servers → Edit
{
  "mcpServers": {
    "playwright-skill": {
      "command": "git",
      "args": [
        "clone",
        "https://github.com/lackeyjb/playwright-skill",
        "~/.claude/skills/playwright-skill"
      ],
      "_inferred": true
    }
  }
}

点击 Cline 侧栏中的 MCP Servers 图标,然后选 "Edit Configuration"。

~/.codeium/windsurf/mcp_config.json
{
  "mcpServers": {
    "playwright-skill": {
      "command": "git",
      "args": [
        "clone",
        "https://github.com/lackeyjb/playwright-skill",
        "~/.claude/skills/playwright-skill"
      ],
      "_inferred": true
    }
  }
}

格式与 Claude Desktop 相同。重启 Windsurf 生效。

~/.continue/config.json
{
  "mcpServers": [
    {
      "name": "playwright-skill",
      "command": "git",
      "args": [
        "clone",
        "https://github.com/lackeyjb/playwright-skill",
        "~/.claude/skills/playwright-skill"
      ]
    }
  ]
}

Continue 使用服务器对象数组,而非映射。

~/.config/zed/settings.json
{
  "context_servers": {
    "playwright-skill": {
      "command": {
        "path": "git",
        "args": [
          "clone",
          "https://github.com/lackeyjb/playwright-skill",
          "~/.claude/skills/playwright-skill"
        ]
      }
    }
  }
}

加入 context_servers。Zed 保存后热重载。

claude mcp add playwright-skill -- git clone https://github.com/lackeyjb/playwright-skill ~/.claude/skills/playwright-skill

一行命令搞定。用 claude mcp list 验证,claude mcp remove 卸载。

使用场景

实战用法: playwright-skill

按需为注册流程编写烟雾测试

👤 想要不手写 Playwright 就能得到测试的开发者 ⏱ ~10 min beginner

何时使用: 你推送了新的注册流程,想知道它端到端是否仍然工作正常。

前置条件
  • Node + Playwright 可安装 — 如果缺少浏览器,技能将通过 npx playwright install 安装
步骤
  1. 描述流程
    使用 playwright 技能。打开 localhost:3000,用 [email protected] / Pass123! 注册,验证我们到达 /dashboard。✓ 已复制
    → Claude 编写 Playwright 脚本,以有头模式运行,报告通过/失败
  2. 交互式调试失败
    它在邮箱输入处失败——在错误前添加截图。✓ 已复制
    → 下一次运行捕获并返回截图

结果: 一次性烟雾测试,你可以选择将其保存为持久规范。

注意事项
  • 选择的选择器很脆弱(例如 nth-child) — 让 Claude 优先使用角色/标签选择器
搭配使用: filesystem

在 3 个视口上快速检查响应式渲染

👤 验证布局变化的前端开发者 ⏱ ~5 min beginner

何时使用: 你改变了头部,想看它在桌面、平板和移动设备上如何渲染。

步骤
  1. 请求截图
    使用 playwright 在 1440、768 和 390 宽度下对 localhost:3000 截图。保存它们。✓ 已复制
    → 3 个 PNG 已保存并返回路径

结果: 三张截图供快速视觉审查。

注意事项
  • 截图不等待字体/图片 — 在截图前添加 networkidle 等待
搭配使用: filesystem

组合

与其他 MCP 搭配,撬动十倍杠杆

playwright-skill + filesystem

将测试规范和截图与它们测试的代码一起保存

编写烟雾测试并将其保存在 tests/e2e/signup.spec.js 下。✓ 已复制
playwright-skill + github

运行测试,使工作流失败,在 PR 上发布结果

针对部署预览运行 playwright 规范,然后作为对 PR #42 的评论发布结果。✓ 已复制
playwright-skill + ios-simulator-skill

Web 用 Playwright,原生用 ios-simulator-skill——在跨平台测试会话中同时使用两者

按顺序运行 playwright web 流程和 ios-simulator 原生流程,报告两者。✓ 已复制

工具

此 MCP 暴露的能力

工具输入参数何时调用成本
Custom Playwright script generation task description 任何浏览器自动化请求 0
run.js executor script path 脚本生成后 0
Headed/headless toggle flag CI 对比本地调试 0

成本与限制

运行它的成本

API 配额
每次调用 Token 数
每次测试运行 1-5k,取决于 Claude 拉入多少 Playwright 参考
费用
免费——你只需要在磁盘上有 Node + Playwright 浏览器
提示
保持提示精准;不要一次性问'测试一切'。

安全

权限、密钥、影响范围

凭据存储: 技能中没有凭据。如果你的测试访问需要认证的页面,将凭据保存在环境变量中——永远不要在生成的脚本中。
数据出站: 仅限你的测试访问的站点

故障排查

常见错误与修复

'browserType.launch: Executable doesn't exist'

运行 npx playwright install chromium

验证: npx playwright --version
选择器间歇性失败

切换到角色/标签选择器;添加 await expect(...).toBeVisible() 等待。

脚本挂起

Claude 可能忘记关闭浏览器。告诉它始终用 try/finally 包装并使用 await browser.close()。

替代方案

playwright-skill 对比其他方案

替代方案何时用它替代权衡
playwright MCP你想要结构化的 MCP 工具(click、fill、snapshot)而不是代码生成MCP 隐藏了代码;这个技能编写可复用的真实脚本
Puppeteer skills / chrome-devtools MCP纯 Chrome 工作流、DevTools 协议功能跨浏览器支持较差

更多

资源

📖 阅读 GitHub 上的官方 README

🐙 查看未解决的 issue

🔍 浏览全部 400+ MCP 服务器和 Skills