Communitygithub.com

Playwright Pro 测试工具包

生产级 Playwright 测试工具包,用于测试生成、修复、迁移及持续集成。

Playwright Pro 测试工具包 是什么?

Playwright Pro 是一款专为 AI 编码代理(如 Claude Code、Cursor)设计的生产级 Playwright 测试工具包。它提供 9 个核心命令,涵盖初始化、测试生成、质量审查、修复失败/不稳定测试、从 Cypress/Selenium 迁移、覆盖率分析以及与 TestRail 和 BrowserStack 的集成。该工具包含 55 个测试模板、3 个专门代理(测试架构师、测试调试器、迁移规划器)以及详细的参考文档,帮助开发者遵循 Playwright 最佳实践(如优先使用 getByRole、避免 waitForTimeout、强制隔离测试)。安装后,通过 `/pw:init` 可快速搭建配置、CI 管道和首次烟雾测试,再通过 `/pw:generate`、`/pw:review`、`/pw:fix` 实现完整的“生成-审查-修复”工作流,确保测试套件的高质量和稳定性。

兼容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/JantonioFC/skillsbank/tree/HEAD/skills/pw

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

Playwright Pro

面向 AI 编码代理的生产级 Playwright 测试工具包。

可用命令

安装为 Claude Code 插件后,以下命令可作为 /pw: 命令使用:

命令功能说明
/pw:init初始化 Playwright — 自动检测框架,生成配置、CI 管道和首个测试
/pw:generate <spec>根据用户故事、URL 或组件生成测试
/pw:review审查测试,检查反模式和覆盖率缺口
/pw:fix <test>诊断并修复失败或不稳定的测试
/pw:migrate从 Cypress 或 Selenium 迁移至 Playwright
/pw:coverage分析已测试部分与缺失部分
/pw:testrail与 TestRail 同步 — 读取案例、推送结果
/pw:browserstack在 BrowserStack 上运行,拉取跨浏览器报告
/pw:report以首选格式生成测试报告

快速入门工作流

推荐大多数项目的执行顺序:

1. /pw:init          → 生成配置、CI 管道和首个烟雾测试
2. /pw:generate      → 根据规格或 URL 生成测试
3. /pw:review        → 验证质量并标记反模式      ← 始终在 generate 之后运行
4. /pw:fix <test>    → 诊断并修复失败/不稳定测试  ← 当 CI 显示红色时运行

验证检查点:

  • 在 /pw:generate 之后 — 始终在提交前运行 /pw:review;它会自动捕获定位器反模式和缺失的断言。
  • 在 /pw:fix 之后 — 在本地重新运行完整套件 (npx playwright test),以确认修复不会引入回归。
  • 在 /pw:migrate 之后 — 运行 /pw:coverage 确认与旧套件的一致性,然后再停用 Cypress/Selenium 测试。

示例:生成 → 审查 → 修复

# 1. 根据用户故事生成测试
/pw:generate "作为用户,我可以使用邮箱和密码登录"

# 生成文件:tests/auth/login.spec.ts
# → Playwright Pro 使用认证模板创建该文件。

# 2. 审查生成的测试
/pw:review tests/auth/login.spec.ts

# → 标记:某个测试使用了 page.locator('input[type=password]') — 建议改用 getByLabel('Password')
# → 自动应用修复。

# 3. 本地运行确认
npx playwright test tests/auth/login.spec.ts --headed

# 4. 如果某个测试在 CI 中不稳定,诊断它
/pw:fix tests/auth/login.spec.ts
# → 识别出缺少 Web 优先断言;将 waitForTimeout(2000) 替换为 expect(locator).toBeVisible()

黄金规则

  1. getByRole() 优于 CSS/XPath — 对标记更改具有弹性
  2. 绝不使用 page.waitForTimeout() — 使用 Web 优先断言
  3. expect(locator) 自动重试;expect(await locator.textContent()) 不会
  4. 每个测试相互隔离 — 测试之间无共享状态
  5. 配置中使用 baseURL — 不硬编码 URL
  6. 重试:CI 中 2 次,本地 0 次
  7. 追踪:'on-first-retry' — 丰富调试且不拖慢速度
  8. 使用 Fixtures 而非全局变量 — 用 test.extend() 管理共享状态
  9. 每个测试一个行为 — 多个相关断言是可以的
  10. 仅模拟外部服务 — 绝不模拟你自己的应用

定位器优先级

1. getByRole()        — 按钮、链接、标题、表单元素
2. getByLabel()       — 带标签的表单字段
3. getByText()        — 非交互文本
4. getByPlaceholder() — 带占位符的输入框
5. getByTestId()      — 当没有语义选项时
6. page.locator()     — CSS/XPath 作为最后手段

包含内容

  • 9 个技能,提供详细的逐步说明
  • 3 个专门代理:测试架构师、测试调试器、迁移规划器
  • 55 个测试模板:认证、CRUD、结账、搜索、表单、仪表盘、设置、入门引导、通知、API、无障碍
  • 2 个 MCP 服务器(TypeScript):TestRail 和 BrowserStack 集成
  • 智能钩子:自动验证测试质量、自动检测 Playwright 项目
  • 6 份参考文档:黄金规则、定位器、断言、fixtures、常见陷阱、不稳定测试
  • 迁移指南:Cypress 和 Selenium 映射表

集成设置

TestRail(可选)

export TESTRAIL_URL="https://your-instance.testrail.io"
export TESTRAIL_USER="[email protected]"
export TESTRAIL_API_KEY="your-api-key"

BrowserStack(可选)

export BROWSERSTACK_USERNAME="your-username"
export BROWSERSTACK_ACCESS_KEY="your-access-key"

快速参考

查看 reference/ 目录中的文件:

  • golden-rules.md — 10 条不可妥协的规则
  • locators.md — 完整的定位器优先级及速查表
  • assertions.md — Web 优先断言参考
  • fixtures.md — 自定义 fixtures 和 storageState 模式
  • common-pitfalls.md — 前 10 个常见错误及其修复
  • flaky-tests.md — 诊断命令和快速修复

查看 templates/README.md 获取完整模板索引。

何时使用

在需要指导或自动化 playwright-pro 相关操作时使用此技能。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

JantonioFC/skillsbank

AI-powered image editing with style transfer and object removal

JantonioFC/skillsbank

Internationalization and localization patterns. Detecting hardcoded strings, managing translations, locale files, RTL support.

JantonioFC/skillsbank

Analise e auditoria de editais de leilao judicial e extrajudicial. Riscos ocultos, clausulas perigosas, debitos, ocupante e classificacao da oportunidade.

JantonioFC/skillsbank

Embed Photopea in web apps using photopea.js. Covers embedding, file I/O, scripting, exporting, layers, text, filters, and the full Photoshop-compatible API.

JantonioFC/skillsbank

Best practices for Remotion - Video creation in React

JantonioFC/skillsbank

Generate walkthrough videos from Stitch projects using Remotion with smooth transitions, zooming, and text overlays

JantonioFC/skillsbank

Seek and analyze video content using Memories.ai Large Visual Memory Model for persistent video intelligence

JantonioFC/skillsbank

Writes complete, structured landing pages optimized for SEO ranking, AEO citation, and visitor conversion. Activate when the user wants to write or generate a landing page for a product, service, or offer.

JantonioFC/skillsbank

Video and audio perception, indexing, and editing. Ingest files/URLs/live streams, build visual/spoken indexes, search with timestamps, edit timelines, add overlays/subtitles, generate media, and create real-time alerts.

JantonioFC/skillsbank

Upload, stream, search, edit, transcribe, and generate AI video and audio using the VideoDB SDK.

JantonioFC/skillsbank

Skill for discovering and researching autonomous AI agents, tools, and ecosystems using the AgentFolio directory.

JantonioFC/skillsbank

Expert in building portfolios that actually land jobs and clients - not just showing work, but creating memorable experiences. Covers developer portfolios, designer portfolios, creative portfolios, and portfolios that convert visitors into opportunities.

JantonioFC/skillsbank

Tool lifecycle UI components for React/Next.js from ui.inference.sh. Display tool calls: pending, progress, approval required, results. Capabilities: tool status, progress indicators, approval flows, results display. Use for: showing agent tool calls, human-in-the-loop approvals, tool output. Triggers: tool ui, tool calls, tool status, tool approval, tool results, agent tools, mcp tools ui, function calling ui, tool lifecycle, tool pending

JantonioFC/skillsbank

Security audit, hardening, threat modeling (STRIDE/PASTA), Red/Blue Team, OWASP checks, code review, incident response, and infrastructure security for any project.

JantonioFC/skillsbank

When the user wants help with paid advertising campaigns on Google Ads, Meta (Facebook/Instagram), LinkedIn, Twitter/X, or other ad platforms. Also use when the user mentions 'PPC,' 'paid media,' 'ROAS,' 'CPA,' 'ad campaign,' 'retargeting,' 'audience targeting,' 'Google Ads,' 'Facebook ads,'...

JantonioFC/skillsbank

Create AI avatar and talking head videos with OmniHuman, Fabric, PixVerse via inference.sh CLI. Models: OmniHuman 1.5, OmniHuman 1.0, Fabric 1.0, PixVerse Lipsync. Capabilities: audio-driven avatars, lipsync videos, talking head generation, virtual presenters. Use for: AI presenters, expla...

JantonioFC/skillsbank

Create AI marketing videos for ads, promos, product launches, and brand content. Models: Veo, Seedance, Wan, FLUX for visuals, Kokoro for voiceover. Types: product demos, testimonials, explainers, social ads, brand videos. Use for: Facebook ads, YouTube ads, product launches, brand awarene...

JantonioFC/skillsbank

Generate AI videos with Google Veo, Seedance, Wan, Grok and 40+ models via inference.sh CLI. Models: Veo 3.1, Veo 3, Seedance 1.5 Pro, Wan 2.5, Grok Imagine Video, OmniHuman, Fabric, HunyuanVideo. Capabilities: text-to-video, image-to-video, lipsync, avatar animation, video upscaling, fole...

JantonioFC/skillsbank

Production-ready CI/CD configurations for Playwright — GitHub Actions, GitLab CI, CircleCI, Azure DevOps, Jenkins, Docker, parallel sharding, reporting, code coverage, and global setup/teardown.

JantonioFC/skillsbank

You are an expert copy editor specializing in marketing and conversion copy. Your goal is to systematically improve existing copy through focused editing passes while preserving the core message.

相关技能