Files
AppAutoTest/conftest.py
CNWei d3f9326baa feat(driver): 新增CoreDriver基础操作,更新文档
- 优化 is_visible,支持快速状态检查。
- 新增 wait_until_visible/wait_until_not_visible 支持元素状态检查。
- 新增 clear_popups 支持弹窗清理。
- 优化 implicit_wait 状态追踪,确保等待时间恢复的准确性。
- 更新 README.md
- 其他优化
[clear_popups 采用“非阻塞探测 + 阻塞确认”策略,大幅提升清理效率并减少无效等待]
2026-01-29 18:17:49 +08:00

73 lines
2.1 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.

#!/usr/bin/env python
# coding=utf-8
"""
@author: CNWei,ChenWei
@Software: PyCharm
@contact: t6g888@163.com
@file: conftest
@date: 2026/1/16 10:52
@desc:
"""
import logging
import pytest
from core.run_appium import start_appium_service, stop_appium_service
from core.driver import CoreDriver
from core.settings import ANDROID_CAPS
@pytest.fixture(scope="session")
def app_server():
"""
第一层:管理 Appium Server 进程。
利用你原本 start_appium_service 里的 40 次轮询和 sys.exit(1) 逻辑。
"""
# 启动服务
service = start_appium_service()
yield service
# 所有测试结束,清理进程
stop_appium_service(service)
@pytest.fixture(scope="module")
def driver(app_server):
"""
第二层:管理 WebDriver 会话。
依赖 app_server确保服务 Ready 后才创建连接。
"""
# 实例化你提供的类结构
app_helper = CoreDriver()
caps = {
"platformName": "Android",
"automationName": "uiautomator2",
"deviceName": "Android",
"appPackage": "com.bocionline.ibmp",
"appActivity": "com.bocionline.ibmp.app.main.launcher.LauncherActivity",
"noReset": False, # 不清除应用数据
"newCommandTimeout": 60
}
# 连接并获取原生 driver 实例
# 这里可以根据需要扩展,比如通过命令行参数选择平台
app_helper.connect(platform="android", caps=caps)
yield app_helper.driver
# 用例结束,只关 session不关 server
app_helper.quit()
def pytest_exception_interact(node, call, report):
"""
当测试用例抛出异常断言失败或代码报错Pytest 会调用这个钩子。
我们在这里手动把错误信息喂给 logging。
"""
# 获取名为 'Error' 的记录器,它会遵循 pytest.ini 中的 log_file 配置
logger = logging.getLogger("Error")
if report.failed:
# 获取详细的错误堆栈(包含 assert 的对比信息)
exc_info = call.excinfo.getrepr(style='no-locals')
logger.error(f"TEST FAILED: {node.nodeid}")
logger.error(f"详细错误信息如下:\n{exc_info}")