Allure2 error - AttributeError: 'function' object has no attribute 'driver'

28 views Asked by At

I’m facing a similar issue. I was trying to add a code to take a screenshot in case any test case failed. can anyone help with this?

code

def pytest_runtest_makereport(item):
outcome = yield
result = outcome.get_result()
if result.failed:
allure.attach(item.function.driver.get_screenshot_as_png(), "Screenshot",  attachment_type=AttachmentType.PNG)%

Here is the error

INTERNALERROR>   File "/usr/local/lib/python3.9/site-packages/pluggy/_callers.py", line 130, in _multicall
INTERNALERROR>     teardown[0].send(outcome)
INTERNALERROR>   File "/app/conftest.py", line 133, in pytest_runtest_makereport
INTERNALERROR>     allure.attach(item.function.driver.get_screenshot_as_png(), "Screenshot",  attachment_type=AttachmentType.PNG)
INTERNALERROR> AttributeError: 'function' object has no attribute 'driver'
0

There are 0 answers