SuperAPI AI 工具集

pw-init

测试与质量

查看项目

更新于 10-16 04:59

技能介绍

用途:在已有项目中搭建可用于生产的 Playwright 端到端(E2E)测试环境。适用于用户提出“set up playwright”“add e2e tests”“configure playwright”“testing setup”“init playwright”等需求时。

主要能力:扫描 package.json 判断框架(React、Next.js、Vue、Angular、Svelte),依据 tsconfig.json 决定使用 TypeScript 还是 JavaScript,检查 Playwright 是否已安装,检查已有测试目录与 CI 配置。随后安装依赖、生成 playwright.config.ts、创建 e2e 目录结构、生成示例测试,并按需生成 GitHub Actions 或 GitLab CI 工作流、更新 .gitignore、添加 npm 脚本。最后运行示例测试并验证结果。

必要用法:安装可执行 npm init playwright@latest -- --quiet,或手动执行 npm install -D @playwright/test 与 npx playwright install --with-deps chromium。生成配置后需按框架调整 baseURL 与 webServer.command,例如 Next.js 用 http://localhost:3000 与 npm run dev,Vite/React 用 http://localhost:5173,Angular 用 http://localhost:4200 与 npm run start;未检测到框架时省略 webServer。npm 脚本包含 test:e2e、test:e2e:ui、test:e2e:debug,运行方式为 npx playwright test 或 npm run test:e2e。

适用场景与限制:适合需要快速接入 Playwright 的前端或全栈项目;未检测到框架时需要用户提供 baseURL,否则留占位符。资料未提供收费、价格、平台兼容细节与效果保证等信息。