用途:调试在 GitHub Actions 中失败的 Playwright E2E 测试。与本地调试不同,trace 位于 CI 工件中,失败可能无法在本地复现,因此以 CI trace 为准。
主要能力:用 gh CLI 定位失败运行并读取失败步骤日志;下载 test-results 工件;用 npx playwright trace 系列命令(open、actions、action、snapshot、requests、console、errors、close)分析失败动作、页面快照、网络与控制台信息;将根因归类为测试缺陷、应用缺陷、环境/配置问题或 flake;按项目 Playwright 脚本规则修复 spec。
使用方式:先确认 gh --version、gh auth status 和 git 远程仓库可用。用 gh run list --branch "$(git branch --show-current)" --status failure --limit 10 或 gh run list --workflow=playwright.yml --status failure --limit 10 找运行,gh run view <run-id> --log-failed 看日志,gh run download <run-id> --name test-results --dir .pw-ci-debug/<run-id>/test-results 下载工件,再 npx playwright trace open <trace.zip> 分析。修复后可用 npx playwright test -g "<exact test title>" --retries 0 本地验证。
适用场景:CI 中失败、本地难复现的 Playwright 测试;需要基于 trace 证据定位根因并按项目规则修复。
限制:需已安装并认证 gh CLI,且仓库有 GitHub 远程;CI 必须启用 tracing(如 trace: 'on-first-retry' 或 'retain-on-failure'),否则无法使用。若根因是应用缺陷或环境问题,不应改测试掩盖。该技能不提交、不推送,由用户自行审查推送。本地无法复现时不能声称已修复。