AGENT SKILL

playwright-best-practices

Provides comprehensive guidance for writing, debugging, and maintaining Playwright tests in TypeScript. Use when writing Playwright tests, fixing flaky tests, debugging failures, implementing Page Object Model, configuring CI/CD, optimizing performance, mocking APIs, handling authentication or OAuth, testing accessibility (axe-core), file uploads/downloads, date/time mocking, WebSockets, geolocation, permissions, multi-tab/popup flows, mobile/responsive layouts, touch gestures, GraphQL, error handling, offline mode, multi-user collaboration, third-party services (payments, email verification), console error monitoring, global setup/teardown, test annotations (skip, fixme, slow), project dependencies, security testing (XSS, CSRF, auth), performance budgets (Web Vitals, Lighthouse), iframes, component testing, canvas/WebGL, service workers/PWA, test coverage, i18n/localization, Electron apps, or browser extension testing. Covers E2E, component, API, visual, accessibility, security, Electron, and extension testing.

License 许可
MIT
最近更新
2026-06-29
Stars
★ 0
Forks
0

01 前言 Front Matter

name
playwright-best-practices
license
MIT
metadata
{ "author": "currents.dev", "version": "1.0" }
description
Provides comprehensive guidance for writing, debugging, and maintaining Playwright tests in TypeScript. Use when writing Playwright tests, fixing flaky tests, debugging failures, implementing Page Object Model, configuring CI/CD, optimizing performance, mocking APIs, handling authentication or OAuth, testing accessibility (axe-core), file uploads/downloads, date/time mocking, WebSockets, geolocation, permissions, multi-tab/popup flows, mobile/responsive layouts, touch gestures, GraphQL, error handling, offline mode, multi-user collaboration, third-party services (payments, email verification), console error monitoring, global setup/teardown, test annotations (skip, fixme, slow), project dependencies, security testing (XSS, CSRF, auth), performance budgets (Web Vitals, Lighthouse), iframes, component testing, canvas/WebGL, service workers/PWA, test coverage, i18n/localization, Electron apps, or browser extension testing. Covers E2E, component, API, visual, accessibility, security, Electron, and extension testing.

02 资源文件 37

03 SKILL.md 正文

Playwright Best Practices

This skill provides comprehensive guidance for all aspects of Playwright test development, from writing new tests to debugging and maintaining existing test suites.

Activity-Based Reference Guide

Consult these references based on what you're doing:

Writing New Tests

When to use: Creating new test files, writing test cases, implementing test scenarios

Activity Reference Files
Writing E2E tests test-organization.md, locators.md, assertions-waiting.md
Writing component tests component-testing.md, test-organization.md
Writing API tests test-organization.md, assertions-waiting.md
Writing visual regression tests test-organization.md, canvas-webgl.md
Structuring test code with POM page-object-model.md, test-organization.md
Setting up test data/fixtures fixtures-hooks.md, test-data.md
Handling authentication fixtures-hooks.md, third-party.md
Testing date/time features clock-mocking.md
Testing file upload/download file-operations.md
Testing accessibility accessibility.md
Testing security (XSS, CSRF) security-testing.md
Using test annotations annotations.md
Testing iframes iframes.md
Testing canvas/WebGL canvas-webgl.md
Internationalization (i18n) i18n.md
Testing Electron apps electron.md
Testing browser extensions browser-extensions.md

Mobile & Responsive Testing

When to use: Testing mobile devices, touch interactions, responsive layouts

Activity Reference Files
Device emulation mobile-testing.md
Touch gestures (swipe, tap) mobile-testing.md
Viewport/breakpoint testing mobile-testing.md
Mobile-specific UI mobile-testing.md, locators.md

Real-Time & Browser APIs

When to use: Testing WebSockets, geolocation, permissions, multi-tab flows

Activity Reference Files
WebSocket/real-time testing websockets.md
Geolocation mocking browser-apis.md
Permission handling browser-apis.md
Clipboard testing browser-apis.md
Camera/microphone mocking browser-apis.md
Multi-tab/popup flows multi-context.md
OAuth popup handling third-party.md, multi-context.md

Debugging & Troubleshooting

When to use: Test failures, element not found, timeouts, unexpected behavior

Activity Reference Files
Debugging test failures debugging.md, assertions-waiting.md
Fixing flaky tests flaky-tests.md, debugging.md, assertions-waiting.md
Debugging flaky parallel runs flaky-tests.md, performance.md, fixtures-hooks.md
Ensuring test isolation / avoiding state leak flaky-tests.md, fixtures-hooks.md, performance.md
Fixing selector issues locators.md, debugging.md
Investigating timeout issues assertions-waiting.md, debugging.md
Using trace viewer debugging.md
Debugging race conditions flaky-tests.md, debugging.md, assertions-waiting.md
Debugging console/JS errors console-errors.md, debugging.md

Error & Edge Case Testing

When to use: Testing error states, offline mode, network failures, validation

Activity Reference Files
Error boundary testing error-testing.md
Network failure simulation error-testing.md, network-advanced.md
Offline mode testing error-testing.md, service-workers.md
Service worker testing service-workers.md
Loading state testing error-testing.md
Form validation testing error-testing.md

Multi-User & Collaboration Testing

When to use: Testing features involving multiple users, roles, or real-time collaboration

Activity Reference Files
Multiple users in one test multi-user.md
Real-time collaboration multi-user.md, websockets.md
Role-based access testing multi-user.md
Concurrent action testing multi-user.md

Refactoring & Maintenance

When to use: Improving existing tests, code review, reducing duplication

Activity Reference Files
Refactoring to Page Object Model page-object-model.md, test-organization.md
Improving test organization test-organization.md, page-object-model.md
Extracting common setup/teardown fixtures-hooks.md
Replacing brittle selectors locators.md
Removing explicit waits assertions-waiting.md
Creating test data factories test-data.md

Infrastructure & Configuration

When to use: Setting up projects, configuring CI/CD, optimizing performance

Activity Reference Files
Configuring Playwright project test-organization.md, projects-dependencies.md
Setting up CI/CD pipelines ci-cd.md, performance.md
Global setup & teardown global-setup.md
Project dependencies projects-dependencies.md
Optimizing test performance performance.md, test-organization.md
Configuring parallel execution performance.md
Isolating test data between workers fixtures-hooks.md, performance.md
Test coverage test-coverage.md

Advanced Patterns

When to use: Complex scenarios, API mocking, network interception

Activity Reference Files
Mocking API responses test-organization.md, network-advanced.md
Network interception network-advanced.md, assertions-waiting.md
GraphQL mocking network-advanced.md
HAR recording/playback network-advanced.md
Custom fixtures fixtures-hooks.md
Advanced waiting strategies assertions-waiting.md
OAuth/SSO mocking third-party.md, multi-context.md
Payment gateway mocking third-party.md
Email/SMS verification mocking third-party.md
Failing on console errors console-errors.md
Security testing (XSS, CSRF) security-testing.md
Performance budgets & Web Vitals performance-testing.md
Lighthouse integration performance-testing.md
Test annotations (skip, fixme) annotations.md
Test steps for reporting annotations.md

Quick Decision Tree

What are you doing?
│
├─ Writing a new test?
│  ├─ E2E test → test-organization.md, locators.md, assertions-waiting.md
│  ├─ Component test → component-testing.md
│  ├─ API test → test-organization.md, assertions-waiting.md
│  ├─ Visual/canvas test → canvas-webgl.md, test-organization.md
│  ├─ Accessibility test → accessibility.md
│  ├─ Mobile/responsive test → mobile-testing.md
│  ├─ i18n/locale test → i18n.md
│  ├─ Electron app test → electron.md
│  ├─ Browser extension test → browser-extensions.md
│  └─ Multi-user test → multi-user.md
│
├─ Testing specific features?
│  ├─ File upload/download → file-operations.md
│  ├─ Date/time dependent → clock-mocking.md
│  ├─ WebSocket/real-time → websockets.md
│  ├─ Geolocation/permissions → browser-apis.md
│  ├─ OAuth/SSO mocking → third-party.md, multi-context.md
│  ├─ Payments/email/SMS → third-party.md
│  ├─ iFrames → iframes.md
│  ├─ Canvas/WebGL/charts → canvas-webgl.md
│  ├─ Service workers/PWA → service-workers.md
│  ├─ i18n/localization → i18n.md
│  ├─ Security (XSS, CSRF) → security-testing.md
│  └─ Performance/Web Vitals → performance-testing.md
│
├─ Test is failing/flaky?
│  ├─ Flaky test investigation → flaky-tests.md
│  ├─ Element not found → locators.md, debugging.md
│  ├─ Timeout issues → assertions-waiting.md, debugging.md
│  ├─ Race conditions → flaky-tests.md, debugging.md
│  ├─ Flaky only with multiple workers → flaky-tests.md, performance.md
│  ├─ State leak / isolation → flaky-tests.md, fixtures-hooks.md
│  ├─ Console/JS errors → console-errors.md, debugging.md
│  └─ General debugging → debugging.md
│
├─ Testing error scenarios?
│  ├─ Network failures → error-testing.md, network-advanced.md
│  ├─ Offline (unexpected) → error-testing.md
│  ├─ Offline-first/PWA → service-workers.md
│  ├─ Error boundaries → error-testing.md
│  └─ Form validation → error-testing.md
│
├─ Refactoring existing code?
│  ├─ Implementing POM → page-object-model.md
│  ├─ Improving selectors → locators.md
│  ├─ Extracting fixtures → fixtures-hooks.md
│  └─ Creating data factories → test-data.md
│
├─ Setting up infrastructure?
│  ├─ CI/CD → ci-cd.md
│  ├─ Global setup/teardown → global-setup.md
│  ├─ Project dependencies → projects-dependencies.md
│  ├─ Test performance → performance.md
│  ├─ Test coverage → test-coverage.md
│  └─ Project config → test-organization.md, projects-dependencies.md
│
└─ Organizing tests?
   ├─ Skip/fixme/slow tests → annotations.md
   ├─ Test steps → annotations.md
   └─ Conditional execution → annotations.md

Test Validation Loop

After writing or modifying tests:

  1. Run tests: npx playwright test --reporter=list
  2. If tests fail:
    • Review error output and trace (npx playwright show-trace)
    • Fix locators, waits, or assertions
    • Re-run tests
  3. Only proceed when all tests pass
  4. Run multiple times for critical tests: npx playwright test --repeat-each=5

04 同仓库更多 Skills

Blake-John
Blake-John/agent-config

websocket-engineer

当使用 WebSocket 或 Socket.IO 构建实时通信系统时使用。适用于双向消息通信、Redis 水平扩展、在线状态追踪、房间管理。

★ 0
Blake-John
Blake-John/agent-config

security-reviewer

识别安全漏洞,生成带有严重性评级的结构化审计报告,并提供可操作的安全修复建议。在开展安全审计、审查代码漏洞或分析基础设施安全时使用。适用于 SAST 扫描、渗透测试、DevSecOps 实践、云安全审查、依赖审计、密钥扫描或合规检查。生成漏洞报告、优先级建议和合规清单。

开发工程师测试与质量Skill与智能体开发
★ 0
Blake-John
Blake-John/agent-config

secure-code-guardian

用于实现认证/授权、保护用户输入或防御 OWASP Top 10 漏洞 —— 包括自定义安全实现,例如使用 bcrypt/argon2 哈希密码、使用参数化语句清理 SQL 查询、配置 CORS/CSP 头部、使用 Zod 验证输入以及设置 JWT token。适用于认证、授权、输入验证、加密、OWASP Top 10 防护、安全会话管理和安全加固。对于预构建的 OAuth/SSO 集成或独立的安全审计,请考虑使用更专业的 skill。

开发工程师
★ 0
Blake-John
Blake-John/agent-config

rust-engineer

编写、审查和调试符合 Rust 风格的代码,确保内存安全和零成本抽象。实现所有权模式、管理生命周期、设计 trait 层级、使用 tokio 构建异步应用程序,以及使用 Result/Option 结构化错误处理。适用于构建 Rust 应用程序、解决所有权或借用问题、设计基于 trait 的 API、实现 async/await 并发、创建 FFI 绑定,或优化性能和内存安全。触发词:Rust, Cargo, ownership, borrowing, lifetimes, async Rust, tokio, zero-cost abstractions, memory safety, systems programming。

开发工程师
★ 0
Blake-John
Blake-John/agent-config

react-native-expert

使用 React Native 和 Expo 构建、优化和调试跨平台移动应用。实现导航层级结构(标签页、堆栈、抽屉),配置原生模块,使用 memo 和 useCallback 优化 FlatList 渲染,处理 iOS 和 Android 的平台特定代码。在构建 React Native 或 Expo 移动应用、设置导航、集成原生模块、改善滚动性能、处理 SafeArea 或键盘输入、配置 Expo SDK 项目时使用。

前端开发
★ 0
Blake-John
Blake-John/agent-config

react-expert

当你使用 .jsx 或 .tsx 文件构建 React 18+ 应用、Next.js App Router 项目或 create-react-app 时使用。创建组件、实现自定义 hooks、调试渲染问题、将类组件迁移为函数组件、以及实现状态管理。适用于 Server Components、Suspense 边界、useActionState 表单、性能优化或 React 19 特性。

前端开发
★ 0