克劳德验收测试
先决条件
- 克劳德代码 安装和工作
- 您的应用程序正在运行 本地(或用于测试的已部署URL)
快速开始
选项A:安装脚本
# From your project root:
bash /path/to/claude-acceptance-tests/install.sh .这将技能、框架规范和示例测试复制到您的项目中。然后将Playwright MCP服务器添加到您的 .mcp.json (见下文)。
选项B:手动设置
- 复制
.claude/skills/run-acceptance-test/进入你的项目.claude/skills/ - 复制
tests/spec/FRAMEWORK_SPEC.md进入你的项目tests/spec/ - 创建
tests/acceptance/为您的测试文件 - 将剧作家MCP添加到您的
.mcp.json
MCP设置
将此添加到您的项目 .mcp.json (如果它不存在,请创建它):
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": ["@anthropic-ai/playwright-mcp@latest"]
}
}
}看 .mcp.json.example 在这个repo中供参考。
写作测试
测试是中的markdown文件 tests/acceptance/ 采用这种结构:
# Test: Descriptive Name
## Metadata
- **Priority**: critical | high | medium | low
- **Area**: auth | dashboard | settings | public | api
- **Requires Auth**: yes | no
- **Estimated Duration**: fast (2min)
## Preconditions
- Application is running at `http://localhost:3000`
## Steps
### Step 1: Load the home page
**Action**: Navigate to `http://localhost:3000/`.
**Expected**: The page loads with a visible navigation bar and hero content.
### Step 2: Click the About link
**Action**: Click the "About" link in the navigation bar.
**Expected**: The browser navigates to `/about`. The page displays a heading with "About".
## Success Criteria
- All pages loaded without errors
- No console errors were logged主要惯例
- 每个文件一个场景。 每个文件都测试一个有凝聚力的用户旅程。
- 订购文件编号:
01-public-pages.md,02-auth-flow.md等等。 - 每一步都有行动+预期。 行动=克劳德所做的。预期=克劳德验证的内容。
- 使用语义描述,而不是选择器。 说“点击登录按钮”而不是“点击
#btn-signin". - 明确成功。 说“页面显示标题为‘仪表板’”,而不是“页面加载正确”。
看 tests/spec/FRAMEWORK_SPEC.md 为了获得完整的规格。
运行测试
在Claude Code中,使用以下技能:
/run-acceptance-test 1 # Run test 01-*.md
/run-acceptance-test all # Run all tests in order
/run-acceptance-test auth # Run tests matching "auth" keyword或者问问克劳德:
在tests/acceptance/01-sample-public-pages.md中运行验收测试
发生了什么
- Claude阅读测试标记并理解所有步骤
- Claude通过Playwright MCP打开浏览器并执行每个步骤
- 每次操作后,Claude都会拍摄一个可访问性快照,以验证预期结果
- Claude报告每一步通过/失败,并附上证据(失败截图)
- 结果保存到
tests/results/YYYY-MM-DD-HH-MM/summary.md
示例演练
包含的样品测试(tests/acceptance/01-sample-public-pages.md)验证在以下位置运行的web应用程序的基本公共页面 http://localhost:3000:
- 加载主页并检查导航栏
- 检查浏览器控制台是否有错误
- 点击“关于”链接并验证导航
- 检查页脚是否存在
- 导航到不存在的URL并验证404页面
这为您提供了一个模板,可以复制并适应您自己的应用程序。
为什么采用这种方法
| 传统E2E测试 | 克劳德+Markdown |
|---|---|
| 易碎的CSS选择器 | Claude使用可访问性快照——对UI更改具有弹性 |
| 复杂的设置(节点、配置、CI) | 零设置——只需markdown文件和Claude |
| 二进制通过/失败 | 取消判断——克劳德可以标记“工作正常,但看起来坏了” |
| 非开发人员很难写 | 任何人都可以用英语写测试 |
| 调试=堆栈跟踪 | 调试=克劳德的叙述+截图 |
许可证
麻省理工学院
