mcpField
P
playwright-skill

playwright-skill

github.com/zebbern测试与质量4.7k41 次安装1 天前更新
代码仓库

关于 playwright-skill

playwright-skill 为使用 Playwright 的开发者提供测试编写与调试指南,涵盖测试设计、CI、框架方案和命令行浏览器操作,并附有 TypeScript 与 JavaScript 示例。

主要功能

  1. 0150 多篇 Playwright 参考指南
  2. 02选择器、断言、夹具与测试组织
  3. 03网络模拟、身份验证与 API 测试
  4. 04CI、调试与测试产物
  5. 05框架适配与迁移指南
  6. 06命令行浏览器自动化指南

适用场景

  1. 01设计可靠的浏览器测试
  2. 02排查不稳定或失败的测试
  3. 03为 Playwright 测试配置 CI
  4. 04使用 Playwright CLI 执行浏览器工作流

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/zebbern/claude-code-guide --skill playwright-skill

安装后在 Claude Code 中输入/playwright-skill确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

ci/
ci-github-actions.md
ci-gitlab.md
ci-other.md
docker-and-containers.md
global-setup-teardown.md
parallel-and-sharding.md
projects-and-dependencies.md
reporting-and-artifacts.md
test-coverage.md
core/
accessibility.md
angular.md
api-testing.md
assertions-and-waiting.md
auth-flows.md
authentication.md
browser-apis.md
browser-extensions.md
canvas-and-webgl.md
clock-and-time-mocking.md
common-pitfalls.md
component-testing.md
configuration.md
crud-testing.md
debugging.md
drag-and-drop.md
electron-testing.md
error-and-edge-cases.md
error-index.md
file-operations.md
file-upload-download.md

详细介绍

Playwright 技能

主张明确、经过生产环境验证的 Playwright 指南——每种模式都说明何时(以及何时不)使用。

50+ 篇参考指南涵盖 Playwright 的完整功能范围:选择器、断言、fixture、页面对象、网络模拟、身份验证、视觉回归、无障碍、API 测试、CI/CD、调试等,并提供 TypeScript 和 JavaScript 示例。

黄金法则

  1. 优先使用 getByRole(),而不是 CSS/XPath——能适应标记变化,也符合用户查看页面的方式
  2. 绝不使用 page.waitForTimeout()——改用 expect(locator).toBeVisible() 或 page.waitForURL()
  3. 使用 Web 优先断言——expect(locator) 会自动重试;expect(await locator.textContent()) 不会
  4. 隔离每项测试——不共享状态,不依赖执行顺序
  5. 在配置中设置 baseURL——测试中不硬编码 URL
  6. 重试次数:CI 中设为 2,本地设为 0——在关键环境中暴露不稳定问题
  7. 跟踪记录:'on-first-retry'——获得丰富的调试产物,同时避免拖慢 CI
  8. 优先使用 fixture,而不是全局变量——通过 test.extend() 共享状态,而不是使用模块级变量
  9. 每项测试只验证一种行为——可以包含多个相关的 expect() 调用
  10. 只模拟外部服务——绝不模拟自己的应用;模拟第三方 API、支付网关和邮件服务

指南索引

Writing Tests
What you're doingGuideDeep dive
Choosing selectorslocators.mdlocator-strategy.md
Assertions & waitingassertions-and-waiting.md
Organizing test suitestest-organization.mdtest-architecture.md
Playwright configconfiguration.md
Page objectspage-object-model.mdpom-vs-fixtures-vs-helpers.md
Fixtures & hooksfixtures-and-hooks.md
Test datatest-data-management.md
Auth & loginauthentication.mdauth-flows.md
API testing (REST/GraphQL)api-testing.md
Visual regressionvisual-regression.md
Accessibilityaccessibility.md
Mobile & responsivemobile-and-responsive.md
Component testingcomponent-testing.md
Network mockingnetwork-mocking.mdwhen-to-mock.md
Forms & validationforms-and-validation.md
File uploads/downloadsfile-operations.mdfile-upload-download.md
Error & edge caseserror-and-edge-cases.md
CRUD flowscrud-testing.md
Drag and dropdrag-and-drop.md
Search & filter UIsearch-and-filter.md
调试与修复
问题指南
通用调试工作流debugging.md
特定错误消息error-index.md
不稳定/间歇性测试flaky-tests.md
常见入门错误common-pitfalls.md
框架实践指南
框架指南
Next.js(App Router + Pages Router)nextjs.md
React(CRA、Vite)react.md
Vue 3 / Nuxtvue.md
Angularangular.md
迁移指南
来源指南
Cypressfrom-cypress.md
Selenium / WebDriverfrom-selenium.md
架构决策
问题指南
应采用哪种定位器策略?locator-strategy.md
端到端测试、组件测试还是 API 测试?test-architecture.md
模拟服务还是真实服务?when-to-mock.md
POM、fixtures 还是 helpers?pom-vs-fixtures-vs-helpers.md
CI/CD 与基础设施
主题指南
GitHub Actionsci-github-actions.md
GitLab CIci-gitlab.md
CircleCI / Azure DevOps / Jenkinsci-other.md
并行执行与分片parallel-and-sharding.md
Docker 与容器docker-and-containers.md
报告与构件reporting-and-artifacts.md
代码覆盖率test-coverage.md
全局设置/清理global-setup-teardown.md
多项目配置projects-and-dependencies.md
专题
主题指南
多用户与协作multi-user-and-collaboration.md
WebSockets 与实时功能websockets-and-realtime.md
浏览器 API(地理位置、剪贴板、权限)browser-apis.md
iframe 与 Shadow DOMiframes-and-shadow-dom.md
Canvas 与 WebGLcanvas-and-webgl.md
Service Worker 与 PWAservice-workers-and-pwa.md
Electron 应用electron-testing.md
浏览器扩展browser-extensions.md
安全测试security-testing.md
性能与基准测试performance-testing.md
i18n 与本地化i18n-and-localization.md
多标签页与弹出窗口multi-context-and-popups.md
时钟与时间模拟clock-and-time-mocking.md
第三方集成third-party-integrations.md
CLI 浏览器自动化
使用场景指南
CLI 浏览器交互playwright-cli/SKILL.md
核心命令(open、click、fill、navigate)core-commands.md
网络模拟与拦截request-mocking.md
运行自定义 Playwright 代码running-custom-code.md
多会话浏览器管理session-management.md
Cookies、localStorage、身份验证状态storage-and-auth.md
从 CLI 生成测试代码test-generation.md
跟踪与调试tracing-and-debugging.md
屏幕截图、视频、PDFscreenshots-and-media.md
设备与环境模拟device-emulation.md
复杂的多步骤工作流advanced-workflows.md

语言说明

所有指南都包含 TypeScript 和 JavaScript 示例。如果项目使用 .js 文件或没有 tsconfig.json,示例会调整为纯 JavaScript。

评论

支持 Markdown