Files
AppAutoTest/utils/decorators.py
CNWei 69b449f5b6 feat(driver,custom_expected_conditions): 增强显式等待, 支持自定义条件
- 引入 custom_expected_conditions 模块,允许通过字符串别名调用。
- 重构 CoreDriver,所有元素查找和操作统一调用 explicit_wait,确保日志和等待逻辑的一致性。
代码。
2026-01-23 11:16:57 +08:00

38 lines
1.1 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