playwright

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Playwright

Playwright

When to Use This Skill

何时使用此Skill

Use this skill when the user:
当用户出现以下情况时使用本Skill:

Mentions / keywords

提及的关键词

  • Mentions “Playwright”, “@playwright/test”, “playwright.config.ts”, “trace viewer”, or “PWDEBUG”
  • References
    *.spec.ts
    /
    *.test.ts
    files that import
    @playwright/test
  • 提及“Playwright”、“@playwright/test”、“playwright.config.ts”、“trace viewer”或“PWDEBUG”
  • 引用了导入
    @playwright/test
    *.spec.ts
    /
    *.test.ts
    文件

Context

场景

  • Is trying to add or maintain E2E/smoke coverage for a web app
  • Is trying to debug flaky UI tests (selectors, timing, waits)
  • Needs one-off automation (screenshots, console logs, quick flow checks)
  • 尝试为Web应用添加或维护E2E/冒烟测试覆盖
  • 尝试调试不稳定的UI测试(选择器、时序、等待)
  • 需要临时自动化操作(截图、控制台日志、快速流程检查)

Purpose

目的

  • Route Playwright work into the right workflow (suite vs. one-off script vs. debugging)
  • Standardize patterns that prevent flaky tests (locators, assertions, waits)
  • Keep artifacts in
    ./tmp/
    for predictable cleanup
  • 将Playwright相关工作引导至正确的工作流(测试套件 vs 临时脚本 vs 调试)
  • 标准化避免测试不稳定的模式(定位器、断言、等待)
  • 将工件存储在
    ./tmp/
    目录下,以便可预测地清理

Quick routing

快速导航

  • Writing/maintaining
    @playwright/test
    suites
    → See
    references/e2e-with-playwright-test.md
  • Auth once, reuse state (
    storageState
    )
    → See
    references/auth-and-storage-state.md
  • CI hardening + config knobs → See
    references/ci-and-config.md
  • Locators, assertions, POM, fixtures → See
    references/patterns.md
  • Fixtures (worker-scoped, auto fixtures) → See
    references/fixtures.md
  • Mocking APIs / controlling network → See
    references/api-mocking.md
  • Visual testing (
    toHaveScreenshot
    )
    → See
    references/visual-testing.md
  • Link checking / dead link detection → See
    references/link-checking.md
  • Flaky tests / trace viewer / retries → See
    references/debugging.md
  • One-off automation (screenshots/logs/check flows) → See
    references/ad-hoc-automation.md
  • 编写/维护
    @playwright/test
    测试套件
    → 查看
    references/e2e-with-playwright-test.md
  • 一次性认证,复用状态(
    storageState
    )
    → 查看
    references/auth-and-storage-state.md
  • CI加固 + 配置项 → 查看
    references/ci-and-config.md
  • 定位器、断言、POM、fixtures → 查看
    references/patterns.md
  • Fixtures(工作进程级、自动fixtures) → 查看
    references/fixtures.md
  • Mock API / 控制网络 → 查看
    references/api-mocking.md
  • 视觉测试(
    toHaveScreenshot
    )
    → 查看
    references/visual-testing.md
  • 链接检查 / 死链检测 → 查看
    references/link-checking.md
  • 不稳定测试 / trace viewer / 重试 → 查看
    references/debugging.md
  • 临时自动化操作(截图/日志/流程检查) → 查看
    references/ad-hoc-automation.md

Non-negotiables

硬性要求

  • Prefer
    getByRole
    /
    getByLabel
    over CSS/XPath; add
    data-testid
    only when needed.
  • Use web-first assertions (
    await expect(locator).toBeVisible()
    ) instead of boolean checks.
  • Never add
    waitForTimeout()
    to “fix” flake; if you use it temporarily while debugging, remove it before calling the work “done”.
  • Don’t default to
    networkidle
    everywhere; use it intentionally (SPAs / known background activity can make it misleading).
  • For CLI agent runs, use minimal reporters to avoid log spam; store artifacts under
    ./tmp/playwright/
    .
  • Keep tests independent; avoid cross-test shared state.
  • 优先使用
    getByRole
    /
    getByLabel
    而非CSS/XPath;仅在必要时添加
    data-testid
  • 使用Web优先断言(
    await expect(locator).toBeVisible()
    )替代布尔值检查。
  • 切勿添加
    waitForTimeout()
    来“修复”测试不稳定问题;如果在调试时临时使用,需在完成工作前移除。
  • 不要在所有场景下默认使用
    networkidle
    ;仅在必要时使用(单页应用/已知的后台活动可能导致其结果不准确)。
  • 对于CLI agent运行,使用极简报告器以避免日志冗余;将工件存储在
    ./tmp/playwright/
    目录下。
  • 保持测试独立性;避免测试间共享状态。

Verification

验证方式

  • E2E suite changes: run
    npx playwright test --reporter=line
    (or
    --reporter=dot
    ) and confirm failures reproduce.
  • Flake fixes: run the previously failing test at least 5 times (ex:
    --repeat-each 5
    ) before calling it fixed.
  • CI-sensitive changes: run the suite in “CI-like” settings (ex:
    CI=1 npx playwright test --reporter=line
    ) and confirm it still behaves.
  • E2E测试套件变更:运行
    npx playwright test --reporter=line
    (或
    --reporter=dot
    )并确认失败场景可复现。
  • 不稳定测试修复:至少运行之前失败的测试5次(例如:
    --repeat-each 5
    )后,再确认问题已修复。
  • 对CI敏感的变更:在“类CI”环境下运行测试套件(例如:
    CI=1 npx playwright test --reporter=line
    )并确认行为符合预期。

Provenance

来源

  • Consolidated from upstream installed skills:
    playwright-best-practices
    ,
    playwright-testing
    ,
    playwright-expert
    ,
    playwright-skill
    ,
    webapp-testing
  • 整合自上游已安装的Skill:
    playwright-best-practices
    ,
    playwright-testing
    ,
    playwright-expert
    ,
    playwright-skill
    ,
    webapp-testing