【发布时间】:2018-03-30 14:46:19
【问题描述】:
我正在尝试将屏幕截图附加到诱惑报告中,现在我正在使用此代码:
@pytest.hookimpl(hookwrapper=True, tryfirst=True)
def pytest_runtest_makereport(item, call):
outcome = yield
rep = outcome.get_result()
setattr(item, "rep_" + rep.when, rep)
return rep
@pytest.fixture(scope="function")
def web_browser(request):
# Open browser:
b = webdriver.PhantomJS()
# Return browser instance to test case:
yield b
# Do teardown (this code will be executed after each test):
if request.node.rep_call.failed:
# Make the screen-shot if test failed:
try:
# Make screen-shot for Allure report:
allure.attach(str(request.function.__name__),
b.get_screenshot_as_png(),
type=AttachmentType.PNG)
except:
pass # just ignore
# Close browser window:
b.quit()
但它不起作用 - 当某些测试失败时,我在报告中看不到任何屏幕截图。
我试过了:
allure.attach(request.function.__name__,
b.get_screenshot_as_png(),
type=AttachmentType.PNG)
allure.attach('screenshot' + str(uuid.uuid4()),
b.get_screenshot_as_png(),
type=allure.attachment_type.PNG)
allure.attach(b.get_screenshot_as_png(),
name='screenshot',
type=AttachmentType.PNG)
allure.attach(b.get_screenshot_as_png(),
name='screenshot2',
type=allure.attachment_type.PNG)
但这些都不起作用......
【问题讨论】:
标签: selenium-webdriver pytest allure