我正在尝试使用 selenium/python pytest-html 保存测试失败时的屏幕截图。
但是,当我运行测试时,它们会被执行,但是,生成报告失败并出现以下错误:
INTERNALERROR> urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=64081): Max retries exceeded with url: /session/5fcf26809181360a0cd1bac02c922697/screenshot (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fe8bd1a1760>: Failed to establish a new connection: [Errno 61] Connection refused'))
这是我的 conftest.py 文件
import os.path
import pytest
from Driver import Driver
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
pytest_html = item.config.pluginmanager.getplugin("html")
outcome = yield
report = outcome.get_result()
extra = getattr(report, "extra", [])
if report.when == "call":
extra.append(pytest_html.extras.url("http://www.website.name/"))
xfail = hasattr(report, "wasxfail")
if (report.skipped and xfail) or (report.failed and not xfail):
report_directory = os.path.dirname(item.config.option.htmlpath)
file_name = report.nodeid.replace("::", "_") + ".png"
destination_file = os.path.join(report_directory, file_name)
Driver.Instance.save_screenshot(destination_file)
if file_name:
html = '<div><img src="%s" alt="screenshot" style="width:300px;height:200px" onclick="window.open(' \
'this.src)" align="right"/></div>' % file_name
extra.append(pytest_html.extras.html(html))
report.extra = extra
这是我的 test.py 文件:
从驱动程序导入 unittest 从 Tests.Transactions.HelperFunctions 导入驱动程序 *
class StreamsTest(unittest.TestCase):
@classmethod
def setUp(cls):
Driver.Initialize()
def testSameDayEverySecond(self):
ConnectSenderWallet()
AppPage.HandleDevAmountsTitleAndAddress()
HandleCreateAndAssert()
@classmethod
def tearDown(cls):
Driver.QuitDriver()
先感谢您