- 优化 is_visible,支持快速状态检查。 - 新增 log_screenshot/log_screenshot_bytes 截图。 - 更新 README.md。 - 其他优化。
55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
import logging
|
|
from functools import wraps
|
|
from typing import Union, Callable
|
|
|
|
|
|
from core.custom_expected_conditions import get_condition
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def resolve_wait_method(func):
|
|
"""
|
|
装饰器:将字符串形式的等待条件解析为可调用的 EC 对象
|
|
"""
|
|
|
|
@wraps(func)
|
|
def wrapper(self, method: Union[Callable, str], *args, **kwargs):
|
|
if isinstance(method, str):
|
|
# 解析格式 "key:arg1,arg2" 或 仅 "key"
|
|
ec_name = method
|
|
ec_args = []
|
|
|
|
if ":" in method:
|
|
ec_name, params = method.split(":", 1)
|
|
if params:
|
|
ec_args = params.split(",")
|
|
|
|
# 委托给 core.custom_expected_conditions.get_condition 处理
|
|
try:
|
|
logger.info(f"解析命名等待条件: '{ec_name}' 参数: {ec_args}")
|
|
method = get_condition(ec_name, *ec_args)
|
|
except Exception as e:
|
|
logger.error(f"解析等待条件 '{method}' 失败: {e}")
|
|
raise e
|
|
|
|
return func(self, method, *args, **kwargs)
|
|
|
|
return wrapper
|
|
|
|
|
|
def exception_capture(func):
|
|
"""
|
|
仅在原子动作失败时,触发 BasePage 层的业务截图逻辑
|
|
"""
|
|
@wraps(func)
|
|
def wrapper(self, *args, **kwargs):
|
|
try:
|
|
return func(self, *args, **kwargs)
|
|
except Exception as e:
|
|
# 自动捕获:调用 BasePage 层的 log_screenshot
|
|
if hasattr(self, "log_screenshot"):
|
|
self.log_screenshot(f"自动异常捕获{func.__name__}")
|
|
raise e
|
|
return wrapper
|