# E2E 测试运行指南 ## 环境准备 ### 1. 启动后端服务 ```bash cd /app/cfc/cfc-backend mvn spring-boot:run # 后端服务运行在 http://localhost:9082 ``` ### 2. 启动前端 H5 服务 ```bash cd /app/cfc/cfc-frontend npm run dev:h5 # 前端 H5 服务运行在 http://localhost:8080 ``` ### 3. 安装 Playwright 依赖 ```bash cd /app/cfc/tests npm install npx playwright install ``` ## 运行测试 ### 运行所有 E2E 测试 ```bash cd /app/cfc/tests npm run test:e2e ``` ### 运行指定流程测试 ```bash # 运行测评订单流程 npx playwright test tests/e2e/assessment-order-flow.spec.js # 运行家庭成员管理流程 npx playwright test tests/e2e/family-member-management.spec.js # 运行心愿兑换流程 npx playwright test tests/e2e/wish-exchange-flow.spec.js ``` ### 调试模式(有 UI) ```bash npm run test:e2e:headed ``` ### 查看测试报告 ```bash npm run test:report # 报告保存在 playwright-report/ 目录 ``` ## 测试文件列表 | 文件 | 描述 | 场景数 | |------|------|--------| | `assessment-order-flow.spec.js` | 测评订单全流程 | 7 | | `family-member-management.spec.js` | 家庭成员管理 | 9 | | `wish-exchange-flow.spec.js` | 心愿兑换审批 | 9 | | `planner-bind-invite.spec.js` | 规划师绑定邀请 | 7 | | `growth-record-sync.spec.js` | 成长记录同步 | 6 | | `energy-system.spec.js` | 能量系统收支 | 6 | | `product-purchase.spec.js` | 商品购买支付 | 9 | | `daily-checkin-streak.spec.js` | 连续签到奖励 | 8 | ## 注意事项 1. **页面路由**:测试使用 uni-app hash 路由格式(如 `/#/pages/assessment/apply`) 2. **元素选择器**:测试使用 CSS class 选择器,需要与前端实现匹配 3. **测试数据**:部分测试需要预设数据(如已绑定的家庭成员、已有的订单等) 4. **超时设置**:复杂操作已设置较长的超时时间 ## 测试覆盖的里程碑 每个测试文件都包含以下里程碑验证: - **Milestone-1**: 流程启动成功(如创建订单、添加成员) - **Milestone-2**: 核心操作成功(如支付、定价) - **Milestone-3**: 状态变更成功 - **Milestone-4**: 数据关联/更新成功 - **Milestone-5**: 完整流程成功 ## 故障排查 ### 问题:页面元素找不到 **原因**:前端页面结构可能与测试选择器不匹配 **解决**: 1. 检查前端页面的实际 class 名称 2. 更新测试中的选择器 3. 使用 `page.waitForSelector()` 等待元素出现 ### 问题:API 请求超时 **原因**:后端服务未启动或响应慢 **解决**: 1. 确保后端服务运行在 9082 端口 2. 增加 timeout 配置 ### 问题:测试数据不存在 **原因**:依赖的数据未初始化 **解决**: 1. 在测试前手动创建所需数据 2. 或在测试中使用 setup 钩子准备数据