refactor(tests): restructure into layered POM architecture with Allure reporting
- Split framework into core/ (config, logger, db, driver factories, screenshot, allure integration) and pages/ (PO layer: base/admin/driver); flatten test files per platform (web/admin, app/driver_android, cross_end) - Slim root conftest.py 656 -> ~100 lines: drop inline CN HTML report, add Allure severity mapping (p0/p1/p2 -> blocker/normal/minor) and environment.properties; support both tests.*-prefixed and bare imports - Preserve TC-D2S-001/002 cross-end E2E cases with business logic unchanged, add allure epic/feature/story/step annotations - Deduplicate: single makereport hook, shared failure-screenshot helpers, single SCREENSHOTS_DIR constant; deterministic auth-state role loading - Move DB credentials from db_helper.py into test_config.yaml (database section) - Move pytest.ini to repo root; switch reporting to allure-pytest (drop pytest-html/junitxml); update requirements.txt accordingly - Delete deprecated scaffolding: test_freight_full_flow + 6 stale page objects, iOS/shipper empty shells, dead utils - Fix flaky vxe-table action-row wait: wait for a visible td instead of hidden placeholder rows (fixed shipper-payment timeouts) - Verified end-to-end against live env: both E2E cases pass (2 passed 3m12s); run artifacts (logs/screenshots/allure) included per repo convention
This commit is contained in:
+43
-60
@@ -1,30 +1,45 @@
|
||||
# 跨端 E2E 测试 — 货运全流程
|
||||
# 跨端 E2E 测试 — 司机接单到管理端核算打款
|
||||
|
||||
## 概述
|
||||
|
||||
`tests/cross_end/` 目录包含跨越多个端(管理端 Web + 司机安卓 APP)的端到端自动化测试,
|
||||
验证从"发布货源"到"平台打款"的**完整业务闭环**。
|
||||
`tests/cross_end/` 包含跨越管理端 Web + 司机安卓 APP 的端到端自动化测试,
|
||||
验证从司机 APP 接单到管理端核算打款的**完整业务闭环**。
|
||||
|
||||
```
|
||||
[管理端 Web] [司机安卓 APP]
|
||||
[司机安卓 APP] [管理端 Web]
|
||||
│ │
|
||||
① 发布货源 ──────────────────────────→│
|
||||
│ ② 接单 │
|
||||
│ ③ 装货 │
|
||||
│ ④ 卸货 │
|
||||
│←────────────────────────────── │
|
||||
⑤ 核算运单 │
|
||||
⑥ 核算审核 │
|
||||
⑦ 货主打款 │
|
||||
⑧ 平台打款给司机 │
|
||||
① 接单(货源→数量→协议) │
|
||||
② 装货(吨位→拍照→合同确认) │
|
||||
③ 卸货(吨位→拍照) │
|
||||
④ 获取运输单号 ──────────────────────→│
|
||||
⑤ 运费核算(无数据时 SQL 重试风控状态)
|
||||
⑥ 运单审核
|
||||
⑦ 垫资-财务打款(含验证码)
|
||||
⑧ 垫资-货主打款
|
||||
```
|
||||
|
||||
## 用例
|
||||
|
||||
| 用例ID | 名称 | 说明 |
|
||||
|---|---|---|
|
||||
| TC-D2S-001 | 司机APP接单到管理端核算打款完整流程 | 基础流程 |
|
||||
| TC-D2S-002 | 司机APP接单到管理端核算打款-车队长全额收款流程 | 核算时选择车队长 + 全额收款模式 |
|
||||
|
||||
页面对象位于 `tests/pages/`(PO 层,与用例分离):
|
||||
|
||||
| Page Object | 文件 | 用途 |
|
||||
|---|---|---|
|
||||
| `DriverFreightFlowPage` | `tests/pages/driver/freight_flow_page.py` | 司机 APP 接单/装货/卸货/取单号 |
|
||||
| `FreightAccountingPage` | `tests/pages/admin/freight_accounting_page.py` | 核算/审核/财务打款/货主打款 |
|
||||
|
||||
元素定位依据: `resources/selectors/正常流程-web端.md`、`resources/selectors/正常流程-司机.md`。
|
||||
|
||||
## 前置条件
|
||||
|
||||
### 管理端
|
||||
|
||||
```bash
|
||||
# 1. 保存管理员登录态 (仅需一次)
|
||||
# 保存管理员登录态 (仅需一次,过期后重跑)
|
||||
python tests/web/admin/save_auth.py --role super_admin --browser chromium
|
||||
```
|
||||
|
||||
@@ -40,8 +55,7 @@ python tests/web/admin/save_auth.py --role super_admin --browser chromium
|
||||
### Python 依赖
|
||||
|
||||
```bash
|
||||
pip install playwright appium-python-client
|
||||
playwright install chromium
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
## 运行
|
||||
@@ -57,46 +71,18 @@ pytest tests/cross_end/ --collect-only
|
||||
pytest tests/ -m "not cross_end"
|
||||
```
|
||||
|
||||
## 测试文件结构
|
||||
## 查看报告 (Allure)
|
||||
|
||||
```
|
||||
tests/cross_end/
|
||||
├── conftest.py # 双 driver fixture (admin_page + app_driver)
|
||||
├── pages/
|
||||
│ ├── admin/
|
||||
│ │ ├── freight_source_page.py # 发布货源 Page Object
|
||||
│ │ ├── waybill_management_page.py # 运单核算 + 审核 Page Object
|
||||
│ │ └── settlement_page.py # 货主打款 + 平台打款 Page Object
|
||||
│ └── app/
|
||||
│ ├── driver_home_page.py # 司机首页 (复用现有)
|
||||
│ ├── driver_order_list_page.py # 订单列表 + 接单 Page Object
|
||||
│ └── driver_transport_page.py # 装货 + 卸货 Page Object
|
||||
├── tests/
|
||||
│ └── test_freight_full_flow.py # 主测试: 8 步全流程
|
||||
└── README.md
|
||||
```bash
|
||||
# 方式一: 直接起本地服务查看(推荐)
|
||||
allure serve output/allure-results
|
||||
|
||||
# 方式二: 生成静态 HTML
|
||||
allure generate output/allure-results -o output/allure-report --clean
|
||||
```
|
||||
|
||||
## 选择器 `⚠️` 标记
|
||||
|
||||
所有新 Page Object 中的定位器 (CSS 选择器 / accessibility_id) 都标有 `# ⚠️`,
|
||||
因为无法从代码静态分析中确定实际 DOM 结构或 APP 元素 ID。
|
||||
|
||||
**替换步骤:**
|
||||
|
||||
### Web 管理端选择器
|
||||
|
||||
1. 启动管理端并登录
|
||||
2. 打开浏览器 DevTools (F12)
|
||||
3. 逐个导航到对应页面(货源管理、运单管理、承运结算)
|
||||
4. 检查每个表单输入框的 `placeholder`、按钮的 `text`、弹窗的 CSS class
|
||||
5. 替换 Page Object 中对应的 `# ⚠️` 选择器
|
||||
|
||||
### APP 端 accessibility_id
|
||||
|
||||
1. 启动 Appium Desktop 并连接到设备
|
||||
2. 使用 Inspector 功能捕获屏幕元素
|
||||
3. 找到每个按钮/输入框的 `accessibility-id` 或 `resource-id`
|
||||
4. 替换 Page Object 中对应的 `# ⚠️` 选择器
|
||||
报告中包含: 用例中文标题/用例ID、P0→BLOCKER 优先级、Phase 步骤树、
|
||||
关键节点截图、失败时自动截图、完整日志。
|
||||
|
||||
## 配置
|
||||
|
||||
@@ -108,26 +94,23 @@ tests/cross_end/
|
||||
| `driver_android` | Appium host, device_name, app_package, no_reset |
|
||||
| `accounts.super_admin` | 管理员手机号/密码 |
|
||||
| `accounts.driver` | 司机手机号/密码 |
|
||||
|
||||
不需要新增配置项。
|
||||
| `database` | MySQL 连接(运费核算无数据时更新风控状态) |
|
||||
|
||||
## 故障排查
|
||||
|
||||
| 现象 | 可能原因 | 解决方案 |
|
||||
|---|---|---|
|
||||
| `pytest.skip: Playwright 未安装` | 环境缺少 playwright | `pip install playwright && playwright install chromium` |
|
||||
| `pytest.skip: Appium-Python-Client 未安装` | 环境缺少 appium | `pip install appium-python-client` |
|
||||
| `pytest.skip: Appium-Python-Client 未安装` | 环境缺少 appium | `pip install Appium-Python-Client` |
|
||||
| 登录态已过期 | storage_state 过期 | `python tests/web/admin/save_auth.py --role super_admin` |
|
||||
| APP 在登录页 | noReset 未生效或首次运行 | 在设备上手动登录一次 |
|
||||
| 无法连接到 Appium server | Appium 未启动 | 终端执行 `appium` |
|
||||
| AdbError / 设备未找到 | 模拟器未启动 | `adb devices` 确认设备在线 |
|
||||
| 订单在 APP 中找不到 | 订单同步延迟 | 在 Page Object 中增加 retry 轮询逻辑 |
|
||||
| `# ⚠️` 选择器错误 | 未更新实际选择器 | 按照上方步骤替换选择器 |
|
||||
| 运费核算查询无数据 | 风控状态未更新 | 用例已自动执行 SQL 重试;仍失败检查 `database` 配置 |
|
||||
|
||||
## 已知限制
|
||||
|
||||
- **仅 chromium**: 管理端不跑 browser matrix,固定使用 chromium
|
||||
- **仅 Android**: APP 端目前固定为 `driver_android`,不跑 iOS
|
||||
- **创建真实数据**: 测试会在环境中创建真实订单,需定期清理或使用测试环境
|
||||
- **无 API 清理**: 测试失败后不会自动取消/删除订单,需手动处理
|
||||
- **同时需要两个环境**: 管理端 + Appium + Android 设备必须同时可用,缺一则 skip
|
||||
- **同时需要两个环境**: 管理端 + Appium + Android 设备必须同时可用
|
||||
|
||||
Reference in New Issue
Block a user