Skip to content

Commit

Permalink
test: verify console logs in UI tests (#1440)
Browse files Browse the repository at this point in the history
**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 <[email protected]>
  • Loading branch information
lplonka-splunk and kkedziak-splunk authored Nov 21, 2024
1 parent 180c28d commit b42d88f
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/ui/conftest.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)

0 comments on commit b42d88f

Please sign in to comment.