def addFailure(self, test, err): self.failure_count += 1 self.status = 1 TestResult.addFailure(self, test, err) _, _exc_str = self.failures[-1] output = self.complete_output() self.result.append((1, test, output, _exc_str)) # if not getattr(test, "driver",""): # pass # else: # try: # driver = getattr(test, "driver") # test.imgs.append(driver.get_screenshot_as_base64()) # except Exception as e: # pass try: driver = WDriver().get_driver() my_log = init_logger() my_log.info("****addFailure****") fail_image = "<img src=\"data:image/png;base64,{}\"/>".format( driver.get_screenshot_as_base64()) log = [str(err), fail_image] self.test_result_list.append( self.gen_case_info(str(test), "addFailure", log)) except Exception as e: print(e) if self.verbosity > 1: sys.stderr.write('F ') sys.stderr.write(str(test)) sys.stderr.write('\n') else: sys.stderr.write('F')
def wrapper(*args, **kw): # print('%s():' % (func.__name__)) with allure.step('添加截图'): allure.attach('添加截图', WDriver().get_driver().get_screenshot_as_png(), type=AttachmentType.PNG) f = func(*args, **kw) with allure.step('添加截图'): allure.attach('添加截图', adb_screen_shot(), type=AttachmentType.PNG) return f
def pytest_runtest_makereport(item, call): ''' hook pytest失败 :param item: :param call: :return: ''' # execute all other hooks to obtain the report object outcome = yield rep = outcome.get_result() # we only look at actual failing test calls, not setup/teardown if rep.when == "call" and rep.failed: mode = "a" if os.path.exists("failures") else "w" with open("failures", mode) as f: # let's also access a fixture for the fun of it if "tmpdir" in item.fixturenames: extra = " (%s)" % item.funcargs["tmpdir"] else: extra = "" f.write(rep.nodeid + extra + "\n") logger.info("测试失败了") with allure.step('添加失败截图...'): allure.attach(rep.nodeid, WDriver().get_driver().get_screenshot_as_png(),type=AttachmentType.PNG)
def __init__(self): self.driver = WDriver().get_driver()
def __init__(self): self.driver = WDriver().get_driver() logger.info("selenum id:{}".format(id(self.driver)))
def __init__(self): logger.info("初始化HomePage") self.driver = WDriver().get_driver() self.func = FunctionPage()
def setUp(self): logger.info("父类初始化") self.driver = WDriver().init_driver() logger.info("selenum id:{}".format(id(self.driver))) self.driver.get("https://www.douban.com")
def __init__(self): logger.info("初始化LoginPage") self.driver = WDriver().get_driver() logger.info("selenum id:{}".format(id(self.driver)))