关于 e2e-test-suite-init
用于搭建 Playwright E2E 测试目录及配套文件的初始化技能。它会先检查是否已有测试套件,遵循 e2e-test-conventions,并按项目配置认证和基础 URL。
主要功能
- 01搭建 e2e/ 目录结构
- 02生成 Playwright 配置与辅助文件
- 03配置认证和环境加载
- 04配置浏览器与测试套件
- 05根据项目调整设置
适用场景
- 01启动 Playwright E2E 测试套件
- 02为项目添加测试基础设施
- 03避免覆盖已有 e2e/ 目录
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ agentmantis/ test-skills --skill e2e-test-suite-init安装后在 Claude Code 中输入/e2e-test-suite-init确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
references/base-page-template.mdenv-config-template.mdfixtures-template.mdplaywright-config-template.md详细介绍
初始化 E2E 测试套件
搭建完整的 e2e/ 目录结构,包含开始编写 Playwright E2E 测试所需的所有配置文件、基类、固件和辅助工具。
前置检查
- 检查
e2e/是否已存在。 如果已存在,则中止并告知用户——切勿覆盖现有测试套件。 - 检查是否已安装 Playwright。 如果
package.json中没有@playwright/test,则添加它。
工作流
步骤 1 — 创建目录结构
e2e/
├── auth/
│ └── auth.setup.ts
├── fixtures/
│ └── base.ts
├── helpers/
│ └── env-config.ts
├── poms/
│ └── base.page.ts
├── test-data/
├── tests/
│ ├── handover/
│ ├── regression/
│ └── smoke/
├── .auth/ # git-ignored, holds saved session state
├── .gitignore
├── .env.example
├── playwright.config.ts
└── tsconfig.json
步骤 2 — 生成配置文件
使用参考模板生成各文件:
| 文件 | 模板参考 |
|---|---|
playwright.config.ts | references/playwright-config-template.md |
poms/base.page.ts | references/base-page-template.md |
fixtures/base.ts | references/fixtures-template.md |
helpers/env-config.ts | references/env-config-template.md |
auth/auth.setup.ts | 参见 e2e-test-conventions 技能中的 references/auth-setup.md |
步骤 3 — 生成支持文件
e2e/.gitignore:
.auth/
.env
.env.*
!.env.example
test-results/
playwright-report/
blob-report/
e2e/.env.example:
BASE_URL="https://your-app.example.com"
LOGIN_EMAIL="[email protected]"
LOGIN_PASSWORD="your-password"
AUTH_FILE="e2e/.auth/user.json"
e2e/tsconfig.json:
{
"compilerOptions": {
"target": "ES2022",
"module": "commonjs",
"moduleResolution": "node",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"outDir": "./dist",
"rootDir": "."
},
"include": ["**/*.ts"],
"exclude": ["node_modules", "dist"]
}
步骤 4 — 适配项目
询问用户(或根据现有代码库推断)以下信息:
- 登录页面 URL — 用于自定义
auth.setup.ts - 登录后 URL — 登录后需要等待的 URL(例如
/dashboard、/home) - 身份验证存储方式 — 仅使用 cookies/localStorage,还是使用 IndexedDB(Firebase、Supabase 等)
- 基础 URL — 默认环境的应用 URL
步骤 5 — 输出后续步骤
生成所有文件后,告知用户:
- 安装 Playwright 浏览器:
npx playwright install - 将
.env.example复制为.env.production并填写值 - 为第一个页面创建 POM:
/create-pom [page-name] - 创建第一个测试:
/create-regression-test [feature]
规则
- 切勿覆盖现有的
e2e/目录 - 所有生成的代码都必须使用 TypeScript
- 所有模式都遵循
e2e-test-conventions技能 - 使用双层 env 加载模式(
getEnvConfig()、getBaseUrl()等) - 身份验证文件路径必须通过
getAuthFilePath()从AUTH_FILE环境变量获取 - 必须在
playwright.config.ts中配置全部五种浏览器 - 必须配置全部三个套件(regression、handover、smoke)
评论
支持 Markdown