Pytest+Selenium是UI自动化常用得框架,结合Allure可以给出优美得测试报告,失败的case可以查看错误日志,但是对于UI自动化来说,最直观的还是可以通过截图来查看失败原因,更方便测试人员定位问题。
钩子函数pytest_runtest_makereport文章来源:https://www.toymoban.com/news/detail-708557.html
pytest提供了pytest_runtest_makereport这个方法,可以捕获用例的执行情况。根据官方提供的示例,在conftest.py文件中添加如下代码就可以捕获每个用例的执行结果。(官方示例链接:
https://docs.pytest.org/en/7.1.x/example/simple.html?highlight=pytest_runtest_makereport)文章来源地址https://www.toymoban.com/news/detail-708557.html
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item, call):
# execute all other hooks to obtain the report object
outcome = yield
rep = outcome.get_result() # rep可以拿到用例的执行结
到了这里,关于Pytest实现用例失败截图并且在测试报告中可以查看的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!