环境:
appium 1.4.13 chromedriver 2.18.343837 Mac 系统
问题
切换到 webview 后,查找元素失败后,会执行截图操作。但实际上,截图失败,并且测试脚本会 hang up, 要强制停止
测试用例脚本:
@user1hod_screen_args()
def test_AA(self):
invest_list =accountPage.Account(self.driver)
username = login_cls[0][2]
password = login_cls[0][3]
logger.info('begin login app')
invest_list.click_tab_me()
loginButton = invest_list.is_element_exists(By.ID,u'com.yingzt.invest:id/summit_btn')
if loginButton:
login(self,username, password)
else:
pass
invest_list.click_my_invest()
sleep(2)
context = self.driver.contexts
self.driver.switch_to.context(u'WEBVIEW_com.yingzt.invest')
invest_list.click_invest_list()
sleep(2)
hh = self.driver.window_handles
sleep(2)
self.driver.switch_to_window(hh[1])
invest_list.click_invest_contract() 这一步查找失败,触发截图
截屏装饰器
@staticmethod
def staticmethod_screen_args(*wargs, **wkargs):
def screen(func):
@wraps(func)
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except:
saveScreen(MyDriver().get_driver(), func.__name__)
import sys
exc_info = sys.exc_info()
raise exc_info[0], None, exc_info[2]
return wrapper
return screen
def saveScreen(driver, name):
time.sleep(1)
now = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time()))
pic_path = filepath+'/image/%s--%s.png' % (name, now)
print u'截图保存路径为:\n%s' % os.path.abspath(pic_path)
driver.get_screenshot_as_file(pic_path)
Appium 日志: