Files
Yb-QaAutomationHub/tests/cross_end/conftest.py
T
xst 18890c0437 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
2026-08-17 14:29:52 +08:00

136 lines
5.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""跨端 E2E fixtures — 同时持有 Playwright (管理端) 和 Appium (司机安卓) 两个 driver。
核心挑战:
pytest 的单端 conftest 各自拥有 page / driver fixture,
跨端测试需要同时注入两者而不冲突。
解决方案: 使用显式命名的 fixture (admin_page / app_driver),
各自独立创建/销毁生命周期,内部统一复用 core 层工厂。
前置条件:
- 管理端: python tests/web/admin/save_auth.py --role super_admin --browser chromium
- 司机安卓: 设备上手动登录一次 (noReset=true 自动复用)
- Appium server: appium (默认 http://localhost:4723)
运行:
pytest tests/cross_end/ -m cross_end -v
"""
import pytest
from tests.core.appium_support import (
create_driver,
make_ensure_logged_in,
save_failure_screenshot,
)
from tests.core.playwright_support import (
admin_browser_page,
save_web_failure_screenshot,
)
# ═══════════════════════════════════════════════════════════════════
# Admin Page (Playwright)
# ═══════════════════════════════════════════════════════════════════
@pytest.fixture
def admin_page(admin_config, request):
"""管理端 Playwright Page — 仅 chromium,加载 super_admin 登录态。
跨端测试已经够慢,不参数化浏览器矩阵。
"""
with admin_browser_page(admin_config, browser_name="chromium", role="super_admin") as (page, _):
yield page
save_web_failure_screenshot(page, request, tag="admin_chromium")
# ═══════════════════════════════════════════════════════════════════
# App Driver (Appium)
# ═══════════════════════════════════════════════════════════════════
@pytest.fixture
def app_driver(driver_android_config, request):
"""司机安卓端 Appium driver。"""
cfg = driver_android_config
d = None
try:
d = create_driver(cfg, platform="android")
yield d
save_failure_screenshot(d, cfg, "android", request)
finally:
if d is not None:
try:
d.quit()
except Exception:
pass
# ═══════════════════════════════════════════════════════════════════
# Login helpers
# ═══════════════════════════════════════════════════════════════════
@pytest.fixture
def ensure_admin_login(admin_config, admin_page, config):
"""确保管理端已登录为 super_admin(跨端流程始终用超管)。"""
def _ensure_login(role: str = "super_admin") -> None:
account = config["accounts"].get(role)
if not account:
raise ValueError(f"未知角色 '{role}',可用: {list(config['accounts'].keys())}")
base_url = admin_config["base_url"]
skip_login = admin_config.get("skip_login", True)
if skip_login:
admin_page.goto(base_url)
admin_page.wait_for_timeout(2000)
if "#/login" not in admin_page.url and "/login" not in admin_page.url:
return
raise RuntimeError(
f"登录态已过期!请运行: python tests/web/admin/save_auth.py --role {role}"
)
# skip_login: false — 实时 UI 登录
from tests.pages.admin.login_page import LoginPage
admin_page.goto(f"{base_url}/#/login")
try:
LoginPage(admin_page).login(account["phone"], account["password"])
except AssertionError as e:
raise RuntimeError(
"登录失败!可能存在图形验证码。请改为手动登录: python tests/web/admin/save_auth.py"
) from e
return _ensure_login
@pytest.fixture
def ensure_driver_login(driver_android_config, config):
"""确保司机安卓端已登录。"""
fn = make_ensure_logged_in(driver_android_config, config, account_role="driver")
return lambda d: fn(d)
# ═══════════════════════════════════════════════════════════════════
# Shared context
# ═══════════════════════════════════════════════════════════════════
@pytest.fixture
def cross_end_context() -> dict:
"""跨端流程共享上下文 — 各步骤通过此 dict 传递数据。
写入:
context["order_no"] = "TEST20260721..."
context["load_confirm"] = True
读取:
order_no = context["order_no"]
"""
return {
"order_no": "",
"waybill_no": "",
"load_confirm": False,
"unload_confirm": False,
"accounting_done": False,
"review_done": False,
}