From b42d88f2bba1b2b182819370908f6eef77e9dc25 Mon Sep 17 00:00:00 2001 From: lplonka-splunk <139213249+lplonka-splunk@users.noreply.github.com> Date: Thu, 21 Nov 2024 10:47:58 +0100 Subject: [PATCH] test: verify console logs in UI tests (#1440) **Issue number:** [ADDON-75613](https://splunk.atlassian.net/browse/ADDON-75613) ## Summary Pytest hook was added to fail test when SEVERE console logs are found. ### Changes > Please provide a summary of what's being changed ### User experience > Please describe what the user experience looks like before and after this change ## Checklist If your change doesn't seem to apply, please leave them unchecked. * [x] I have performed a self-review of this change * [ ] Changes have been tested * [ ] Changes are documented * [x] PR title follows [conventional commit semantics](https://www.conventionalcommits.org/en/v1.0.0/) --------- Co-authored-by: kkedziak --- tests/ui/conftest.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) 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)