Files
QaAutomationHub/tests/core/allure_support.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

42 lines
1.4 KiB
Python

"""Allure 集成辅助 — 截图附件 + 报告环境信息。
allure-pytest 未安装时所有函数静默降级(截图仍保存到本地文件)。
"""
from pathlib import Path
try:
import allure
except ImportError: # pragma: no cover
allure = None
def attach_png(path: str, name: str = "screenshot") -> None:
"""把 PNG 文件附加到 Allure 报告当前用例/步骤上。"""
if allure is None:
return
try:
allure.attach.file(path, name=name, attachment_type=allure.attachment_type.PNG)
except Exception:
pass # 附件失败不影响用例主流程
def write_environment_properties(results_dir: str, config: dict) -> None:
"""向 allure-results 目录写入 environment.properties(报告环境页展示)。"""
if not results_dir:
return
admin = config.get("admin", {})
lines = [
f"base_url={admin.get('base_url', '')}",
f"browsers={','.join(admin.get('browsers', []))}",
f"skip_login={admin.get('skip_login', '')}",
"platform=Windows",
"project=运八网络货运平台",
]
# Allure 按 ISO-8859-1 解析 properties,非 ASCII 内容转 \uXXXX 防乱码
content = "\n".join(lines) + "\n"
content = content.encode("ascii", "backslashreplace").decode("ascii")
out_dir = Path(results_dir)
out_dir.mkdir(parents=True, exist_ok=True)
(out_dir / "environment.properties").write_text(content, encoding="ascii")