You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an automation framework with selenium/pytest with some fixtures in the test modules which execute repetitive code.
In case the execution fails in the fixture this is marked as ERROR in the html report and despite being able to take a screenshot on this occurrence it is not attached to the report.
A few more details :
report.when == "setup"
report.failed is True
the extraHTML div is empty in the report
the same mechanism is used to attach the screenshot successfully if the failure occurs in the test code.
Example test & fixture
@pytest.fixture(autouse=True)
def open_userdata_page(vi_rewrite_gui):
"""
Autouse fixture which opens userdata page before each test
"""
vi_rewrite_gui.open_userdata_page(shortname)
def test_validation_errors(vi_rewrite_gui):
"""
Check validation errors when trying to proceed without filling any info
"""
vi_rewrite_gui.click_continue_btn()
actual_validation_errors = vi_rewrite_gui.get_validation_errors()
assert expected_validation_errors == actual_validation_errors
Conftest hook
@pytest.mark.hookwrapper
def pytest_runtest_makereport(item):
pytest_html = item.config.pluginmanager.getplugin('html')
outcome = yield
report = outcome.get_result()
report.description = str(item.function.__doc__)
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):
driver = DRIVER_REGISTRY.get(item.nodeid)
if driver:
# driver = item.funcargs['driver_mod']
timestamp = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
screenshot_name = f"{item.name}_{timestamp}.png"
driver.save_screenshot(os.path.join(SCREENSHOTS_PATH, screenshot_name))
build_img_path_and_div_for_html(screenshot_name, extra, pytest_html)
report.extra = extra
The text was updated successfully, but these errors were encountered:
vladimir-popescu-idnow
changed the title
How to add screenshot to report when status is ERROR
How to add screenshot to report when result is ERROR
Oct 26, 2024
Hello,
I have an automation framework with selenium/pytest with some fixtures in the test modules which execute repetitive code.
In case the execution fails in the fixture this is marked as ERROR in the html report and despite being able to take a screenshot on this occurrence it is not attached to the report.
A few more details :
Example test & fixture
Conftest hook
The text was updated successfully, but these errors were encountered: