写关键字驱动的自动化框架时候发现,针对关键字方法的代码比较多和复杂,于是考虑重新写了个类调用这些方法,但感觉上会有些麻烦,有没更好的建议?
例子:
封装了ActionMethod类,处理操作逻辑:
class ActionMethod:
"""封装操作类"""
@exe_record
@func_set_timeout(120)
def click_element(self, driver, obj, data):
"""点击元素"""
e_time = None
if data == 0 or data is None or data == '':
pass
elif ';' in data:
s_time = data.split(';')[0]
e_time = data.split(';')[1]
if s_time == '0' or s_time is None or s_time == '':
pass
else:
time.sleep(int(s_time))
else:
time.sleep(int(data))
element = GetByLocal.get_clickable_element(driver, obj)
try:
time.sleep(0.5)
element.click()
except ElementClickInterceptedException:
driver.execute_script('arguments[0].click()', self.get_element(driver, obj))
self.logger.get_logger().warning('无法点击,故使用JS点击尝试')
if e_time and e_time != '':
time.sleep(int(e_time))
再封装了CaseOperation类调用ActionMethod类:
class CaseOperation:
def __init__(self):
"""初始化操作对象"""
self.action_method = ActionMethod()
def click_element(self, driver, obj, data=0):
"""
说明...
"""
self.action_method.click_element(driver, obj, data)
目前采用的是这种形式,有没大神有更好的建议。
接口可以用abc库试试