feat(driver,custom_expected_conditions): 增强显式等待, 支持自定义条件
- 引入 custom_expected_conditions 模块,允许通过字符串别名调用。 - 重构 CoreDriver,所有元素查找和操作统一调用 explicit_wait,确保日志和等待逻辑的一致性。 代码。
This commit is contained in:
@@ -2,19 +2,36 @@ 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):
|
||||
# TODO: 这里可以接入 custom_ec 字典进行查找
|
||||
# method = custom_ec.get(method, lambda x: False)
|
||||
logger.info(f"解析命名等待条件: '{method}'")
|
||||
# 保持原有逻辑作为占位
|
||||
method = lambda _: False
|
||||
# 解析格式 "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
|
||||
|
||||
return wrapper
|
||||
|
||||
Reference in New Issue
Block a user