python - 将屏幕截图添加到 Pytest Html 报告时出错
问题描述
我无法在所需的 html 报告中添加失败的 Scanerios 的屏幕截图。我所做的只是在其他所需文件夹中移动了 html 报告的创建,并且我收到屏幕截图未放置在 HTML 报告中的错误 下面是我在 conftest 中的 ScreenShot 代码
@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.failed and not xfail):
file_name = report.nodeid.replace("::", "_") + ".png"
_capture_screenshot(file_name)
if file_name:
html = '<div><img src="%s" alt="screenshot" style="width:304px;height:228px;" ' \
'onclick="window.open(this.src)" align="right"/></div>' % file_name
extra.append(pytest_html.extras.html(html))
report.extra = extra
def _capture_screenshot(name):
driver.get_screenshot_as_file(name)
解决方案
推荐阅读
- reactjs - 当您使用 multipart/form-data 内容类型拥有 javascript 对象时如何发布数据
- python - groupby 导致空数据框
- node.js - Amazon Rekogntion Image:错误 InvalidImageFormatException:请求的图像格式无效
- javascript - 将表单的复选框标签附加到
元素
- vue.js - Vue3 - 如何获取版本
- matlab - 是否可以从未经校准的校正图像对确定两个相机之间的基线?
- apache - Joomla:从 example.com/index.php/foo/bar 永久重定向到 example.com/foo/bar(URL 中没有 index.php)
- algorithm - 算法效率的大符号
- python - 循环遍历 IP 地址范围以检查 HTML 中的打印机状态 - Python & BeuatifulSoup
- node.js - Stripe - 使用正确的反应前端组件进行信用卡存储?