如何使用屏幕截图生成HTML报告

时间:2020-05-06 02:04:10

标签: pytest pytest-html

导入pytest

将uiautomator2导入为u2

d = u2.connect()

def test_precondition():

d.press(“home”)

def test_procedure():

d(text=“Settings”).click()

d.screenshot(“Settings.png”)

d(text=“Bluetooth”).click()

d.screenshot(“Bluetooth.png”)

def test_expectedResult():

assert d(text=“Bluetooth”).exists

在上述脚本上运行为:py.test --html = report.html --self-contained-html蓝牙settings.py

我是python的新手,当我使用pytest运行上述脚本并生成HTML报告时,我无法在HTML报告中看到截图图像,要求提供解决方案

1 个答案:

答案 0 :(得分:0)

默认情况下,pytest-html会捕获并附加仅针对失败的测试用例的屏幕截图,如果您也希望它也为通过的测试用例捕获屏幕快照。您可以引用以下线程Here