feat: 基于 UI 自动化最佳实践的测试框架骨架搭建

- tests/config: 环境配置 (.yaml) + 配置加载器
- tests/utils: 日志工具 + 测试数据生成器
- tests/web: Playwright conftest + Page Object 基类 + 登录页 + 导航栏组件 + 登录用例(6条)
- tests/app: Appium conftest + Page Object 基类 + 司机端首页 + 登录用例(3条)
- pytest.ini: markers(p0/p1/p2/smoke/web/app) + 运行配置
- 所有用例按最佳实践采用 Page Object 模式 + data-testid 优先定位 + 失败自动截图
This commit is contained in:
xst
2026-07-15 10:24:22 +08:00
parent 26ef99f7e7
commit aade9e39d0
17 changed files with 1034 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
"""统一日志工具。
Usage:
from tests.utils.logger import get_logger
logger = get_logger(__name__)
logger.info("开始执行用例")
logger.error(f"用例失败: {e}")
"""
import logging
import sys
from datetime import datetime
from pathlib import Path
# 日志目录
LOGS_DIR = Path("output/logs")
LOGS_DIR.mkdir(parents=True, exist_ok=True)
# 日志格式
_FORMAT = "%(asctime)s [%(levelname)s] %(name)s%(message)s"
_DATE_FMT = "%Y-%m-%d %H:%M:%S"
# 根 logger 配置(模块级,只初始化一次)
_ROOT_LOGGER = logging.getLogger("tests")
_ROOT_LOGGER.setLevel(logging.DEBUG)
# 控制台 Handler
_console_handler = logging.StreamHandler(sys.stdout)
_console_handler.setLevel(logging.INFO)
_console_handler.setFormatter(logging.Formatter(_FORMAT, datefmt=_DATE_FMT))
# 文件 Handler(每次运行一个日志文件)
_log_file = LOGS_DIR / f"test_run_{datetime.now().strftime('%Y%m%d_%H%M%S')}.log"
_file_handler = logging.FileHandler(_log_file, encoding="utf-8")
_file_handler.setLevel(logging.DEBUG)
_file_handler.setFormatter(logging.Formatter(_FORMAT, datefmt=_DATE_FMT))
_ROOT_LOGGER.addHandler(_console_handler)
_ROOT_LOGGER.addHandler(_file_handler)
def get_logger(name: str) -> logging.Logger:
"""获取以 `tests.` 为前缀的子 logger。"""
if not name.startswith("tests."):
name = f"tests.{name}"
return logging.getLogger(name)