1、先pip安装插件: pytest-html、pytest-rerunfailures
2、用例执行失败自动截图到报告内 ,这个其实可以写到conftest.py文件。
当运行用例时遇到错误就会自己调用截图方法,并把截图存到html报告内
#固定脚本,可根据需要更改
from selenium import webdriver
import pytest
import os
driver = None
@pytest.mark.hookwrapper
def pytest_runtest_makereport(item):
"""
Extends the PyTest Plugin to take and embed screenshot in html report, whenever test fails.
:param item:
"""
pytest_html = item.config.pluginmanager.getplugin('html')
outcome = yield
report = outcome.get_result()
extra = getattr(report, 'extra', [])
if report.when == 'call' or report.when == "setup":
xfail = hasattr(report, 'wasxfail')
if (report.skipped and xfail) or (report.