def open(step): element = step['element'] value = e.get(element)[1] if step['data'].get('清理缓存', '') or step['data'].get('clear', ''): g.driver.delete_all_cookies() if step['data'].get('打开方式', '') == '新标签页' or step['data'].get('mode', '').lower() == 'tab': js = "window.open('%s')" % value g.driver.execute_script(js) # 判断是否打开了新的窗口,并将新窗口添加到所有窗口列表里 all_handles = g.driver.window_handles for handle in all_handles: if handle not in w.windows.values(): w.register(step, handle) else: if step['data'].get('打开方式', '') == '新浏览器' or step['data'].get('mode', '').lower() == 'browser': w.close() g.set_driver() w.init() g.driver.get(value) w.open(step) cookie = step['data'].get('cookie', '') if cookie: g.driver.add_cookie(json2dict(cookie)) co = g.driver.get_cookie(json2dict(cookie).get('name', '')) logger.info(f'cookie is add: {co}') sleep(0.5)
def open(step): element = step['element'] el, value = e.get(element) if step['data'].get('清理缓存', '') or step['data'].get('cookie', ''): g.driver.delete_all_cookies() if step['data'].get('打开方式', '') == '新标签页' or step['data'].get('mode', '').lower() == 'tab': js = "window.open('%s')" % value g.driver.execute_script(js) # 判断是否打开了新的窗口,并将新窗口添加到所有窗口列表里 all_handles = g.driver.window_handles for handle in all_handles: if handle not in w.windows.values(): w.register(step, handle) else: if step['data'].get('打开方式', '') == '新浏览器' or step['data'].get('mode', '').lower() == 'browser': w.close() g.set_driver() w.init() g.driver.get(value) w.open(step) sleep(0.5)
'Run the testcase: %s|%s Fail, SETUP is not Pass. Break the AutoTest' % (testcase['id'], testcase['title'])) break except Exception as exception: case.error( 'Error', 'Remark:%s |||Exception:%s' % (testcase['remark'], exception)) logger.exception('Run the testcase: %s|%s fail' % (testcase['id'], testcase['title'])) if testcase['condition'].lower() == 'base': logger.warn( 'Run the testcase: %s|%s Error, BASE is not Pass. Break the AutoTest' % (testcase['id'], testcase['title'])) break if testcase['condition'].lower() == 'setup': logger.warn( 'Run the testcase: %s|%s Error, SETUP is not Pass. Break the AutoTest' % (testcase['id'], testcase['title'])) break self.report.finish() # 2.清理环境 try: if g.platform.lower() in ('desktop', ): w.close() g.driver.quit() logger.info('--- Quit th Driver: %s' % g.browserName) except: logger.exception('Clear the env is fail')