用途:为 Web 应用编写与维护 Playwright 浏览器、端到端及 API 测试,适合用户流程、路由与重定向、对话框交互、SPA 异步导航等场景,也可通过 APIRequestContext 直接测试接口。
主要能力:提供测试目录按功能域组织、自定义 fixture 导入、helper 函数、beforeEach 共享设置、test.step() 分步流程、选择器优先级(getByRole、getByText、getByTestId)、断言模式、page.route() 模拟接口与外部依赖、worker 级认证 fixture、Valibot 类型安全解析、401 未认证测试等约定。
必要用法:若项目有扩展 test 对象的 fixture 文件,从该文件导入 test 与 expect;否则从 @playwright/test 导入,类型用 import type。常用命令:npx playwright test、npx playwright test 指定文件、npx playwright test --ui、npx playwright test --headed、npx playwright test --debug、npx playwright show-report。应查看 package.json 中的测试脚本。
限制与注意事项:mock 不应产生真实依赖无法产生的状态;最终 UI 不足以证明请求被取消;正则使用 /u 标志;仅在位置本身是测试行为时才用 .first()/.nth()。资料未提供官方文档链接、版本要求、收费信息或并行/CI 细节。