diff --git a/tests/ui/conftest.py b/tests/ui/conftest.py index 7a758fec1..5bf78fa18 100644 --- a/tests/ui/conftest.py +++ b/tests/ui/conftest.py @@ -1,7 +1,15 @@ +from typing import Any, Iterator + import pytest from tests.ui.pages.account_page import AccountPage from tests.ui.test_configuration_page_account_tab import _ACCOUNT_CONFIG +from pytest_splunk_addon_ui_smartx import utils as s_utils + +from _pytest.assertion import truncate + +truncate.DEFAULT_MAX_LINES = 9999 +truncate.DEFAULT_MAX_CHARS = 9999 @pytest.fixture @@ -13,3 +21,30 @@ def add_delete_account(ucc_smartx_rest_helper): kwargs = _ACCOUNT_CONFIG yield account.backend_conf.post_stanza(url, kwargs) account.backend_conf.delete_all_stanzas() + + +@pytest.hookimpl(hookwrapper=True) +def pytest_runtest_call(item: pytest.Item) -> Iterator[Any]: + """ + Implemented hook to: + - check browser logs for severe logs after each test run. + """ + + yield + + IGNORED = { + "appLogo.png - Failed to load resource: the server responded with a status of 404 (Not Found)", + } + + browser_logs = s_utils.get_browser_logs(item.selenium_helper.browser) + severe_logs = [ + log + for log in browser_logs + if log.level == s_utils.LogLevel.SEVERE + and not any(ignored in log.message for ignored in IGNORED) + ] + + if severe_logs: + log_msg = [f"{log.level}: {log.source} - {log.message}" for log in severe_logs] + msg = "Severe logs found in browser console logs: \n" + "\n".join(log_msg) + pytest.fail(msg, pytrace=True)