feat: 重构测试框架 — 覆盖 6 端 (管理端 + 小程序 + 4 个移动端)
目录结构: tests/web/admin/ 管理端 (Playwright) tests/web/mini_program/ 司机端小程序 (Playwright/微信 WebView) tests/app/driver_android/ 司机安卓 (Appium) tests/app/shipper_android/ 货主安卓 (Appium) tests/app/driver_ios/ 司机苹果 (Appium) tests/app/shipper_ios/ 货主苹果 (Appium) 公共模块: tests/app/_shared.py driver+ensure_logged_in 工厂 tests/app/_base_page.py App Page Object 基类 配置: test_config.yaml 拆分为 6 个独立 section + 货主账号
This commit is contained in:
+42
-6
@@ -1,27 +1,63 @@
|
||||
"""根级 conftest — 全局 fixture:配置加载、日志、测试数据清理。
|
||||
"""根级 conftest — 全局 fixture:配置加载、日志。
|
||||
|
||||
自动应用于 tests/ 下所有测试模块。
|
||||
Usage:
|
||||
def test_xxx(admin_config): # 管理端配置
|
||||
def test_xxx(driver_android_config): # 司机安卓配置
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
# 将 tests/ 目录加入 Python path,确保 `from tests.xxx import yyy` 可用
|
||||
import sys
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def config():
|
||||
"""全局配置 fixture(session 级别,只加载一次)。"""
|
||||
"""全局配置(session 级,只加载一次)。"""
|
||||
from tests.config.test_config import load_config
|
||||
return load_config()
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def logger(request):
|
||||
"""每个测试函数一个 logger,自动以模块名命名。"""
|
||||
"""每个测试函数的 logger。"""
|
||||
from tests.utils.logger import get_logger
|
||||
module_name = request.module.__name__.replace("tests.", "")
|
||||
return get_logger(module_name)
|
||||
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════════
|
||||
# 各端配置 fixture(从 config 中摘取对应 section)
|
||||
# ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def admin_config(config):
|
||||
"""管理端 (Playwright) 配置。"""
|
||||
return config["admin"]
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def mini_program_config(config):
|
||||
"""司机端小程序 (Playwright) 配置。"""
|
||||
return config["mini_program"]
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def driver_android_config(config):
|
||||
"""司机安卓端 (Appium) 配置。"""
|
||||
return config["driver_android"]
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def shipper_android_config(config):
|
||||
"""货主安卓端 (Appium) 配置。"""
|
||||
return config["shipper_android"]
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def driver_ios_config(config):
|
||||
"""司机苹果端 (Appium) 配置。"""
|
||||
return config["driver_ios"]
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def shipper_ios_config(config):
|
||||
"""货主苹果端 (Appium) 配置。"""
|
||||
return config["shipper_ios"]
|
||||
|
||||
Reference in New Issue
Block a user