TA的每日心情 | 擦汗 前天 09:07 |
---|
签到天数: 527 天 连续签到: 4 天 [LV.9]测试副司令
|
1测试积点
写关键字驱动的自动化框架时候发现,针对关键字方法的代码比较多和复杂,于是考虑重新写了个类调用这些方法,但感觉上会有些麻烦,有没更好的建议?
例子:
封装了ActionMethod类,处理操作逻辑:
- <p>class ActionMethod:
- """封装操作类"""</p><p>@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))</p>
复制代码
再封装了CaseOperation类调用ActionMethod类:
- <p>class CaseOperation:
- def __init__(self):
- """初始化操作对象"""
- self.action_method = ActionMethod()</p><p>def click_element(self, driver, obj, data=0):
- """
- 说明...
- """
- self.action_method.click_element(driver, obj, data)</p>
复制代码
目前采用的是这种形式,有没大神有更好的建议。
|
|