mcpField
E
e2e-test-suite-init

e2e-test-suite-init

github.com/agentmantis测试与质量12122 次安装29 周前更新
代码仓库

关于 e2e-test-suite-init

用于搭建 Playwright E2E 测试目录及配套文件的初始化技能。它会先检查是否已有测试套件,遵循 e2e-test-conventions,并按项目配置认证和基础 URL。

主要功能

  1. 01搭建 e2e/ 目录结构
  2. 02生成 Playwright 配置与辅助文件
  3. 03配置认证和环境加载
  4. 04配置浏览器与测试套件
  5. 05根据项目调整设置

适用场景

  1. 01启动 Playwright E2E 测试套件
  2. 02为项目添加测试基础设施
  3. 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.md
env-config-template.md
fixtures-template.md
playwright-config-template.md

详细介绍

初始化 E2E 测试套件

搭建完整的 e2e/ 目录结构,包含开始编写 Playwright E2E 测试所需的所有配置文件、基类、固件和辅助工具。


前置检查

  1. 检查 e2e/ 是否已存在。 如果已存在,则中止并告知用户——切勿覆盖现有测试套件。
  2. 检查是否已安装 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.tsreferences/playwright-config-template.md
poms/base.page.tsreferences/base-page-template.md
fixtures/base.tsreferences/fixtures-template.md
helpers/env-config.tsreferences/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 — 适配项目

询问用户(或根据现有代码库推断)以下信息:

  1. 登录页面 URL — 用于自定义 auth.setup.ts
  2. 登录后 URL — 登录后需要等待的 URL(例如 /dashboard、/home)
  3. 身份验证存储方式 — 仅使用 cookies/localStorage,还是使用 IndexedDB(Firebase、Supabase 等)
  4. 基础 URL — 默认环境的应用 URL
步骤 5 — 输出后续步骤

生成所有文件后,告知用户:

  1. 安装 Playwright 浏览器:npx playwright install
  2. 将 .env.example 复制为 .env.production 并填写值
  3. 为第一个页面创建 POM:/create-pom [page-name]
  4. 创建第一个测试:/create-regression-test [feature]

规则

  • 切勿覆盖现有的 e2e/ 目录
  • 所有生成的代码都必须使用 TypeScript
  • 所有模式都遵循 e2e-test-conventions 技能
  • 使用双层 env 加载模式(getEnvConfig()、getBaseUrl() 等)
  • 身份验证文件路径必须通过 getAuthFilePath() 从 AUTH_FILE 环境变量获取
  • 必须在 playwright.config.ts 中配置全部五种浏览器
  • 必须配置全部三个套件(regression、handover、smoke)

评论

支持 Markdown