Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make browser log level threshold configurable #39

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
User = namedtuple('User', ['username', 'password', 'name'])


def pytest_configure(config):
config.addinivalue_line('markers', 'internal: mark test as a self test')


def pytest_generate_tests(metafunc):
variables = metafunc.config._variables # pylint: disable=protected-access

Expand Down
28 changes: 25 additions & 3 deletions tests/test_pages.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# pylint: disable=redefined-outer-name
from __future__ import print_function

from enum import IntFlag
from typing import Union, KeysView, List
from urllib.parse import ParseResult, urlparse, parse_qs, urlencode

Expand All @@ -12,6 +13,10 @@
from selenium.common.exceptions import TimeoutException


# https://github.com/SeleniumHQ/selenium/wiki/Logging
BrowserLogLevel = IntFlag('BrowserLogLevel', ['ALL', 'DEBUG', 'INFO', 'WARNING', 'SEVERE', 'OFF'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My brain wants to argue that ALL and OFF are not actually levels, more "filter settings" (even tho they are defined as suchin the wiki and also https://www.selenium.dev/documentation/legacy/json_wire_protocol/#log-levels), but at the same time, it doesn't really hurt as long as we're comparing them as IntFlags here 🤷‍♀️



EXCLUDE_ERRORS = (
# Fixed in Foreman 3.7 - https://projects.theforeman.org/issues/36093
'Scrollbar test exception: TypeError:',
Expand Down Expand Up @@ -52,7 +57,7 @@ def filtered_url_query(url: str, allowed_query_params: Union[List, KeysView]) ->

@pytest.mark.nondestructive
@pytest.mark.selenium
def test_menu_item(selenium, user, url):
def test_menu_item(selenium, user, url, variables):
selenium.get(url)
assert selenium.current_url.endswith('/users/login'), 'Redirect to login page'
login_field = selenium.find_element(By.NAME, 'login[login]')
Expand Down Expand Up @@ -82,5 +87,22 @@ def test_menu_item(selenium, user, url):
print("https://github.com/mozilla/geckodriver/issues/284")

logs = selenium.get_log('browser')
severe_messages = [x['message'] for x in logs if x.get('level') == 'SEVERE' and not any(excl in x['message'] for excl in EXCLUDE_ERRORS)]
assert severe_messages == [], 'Error messages with log level SEVERE in browser console'
threshold = BrowserLogLevel[variables.get('browser_log_threshold', 'SEVERE')]
messages = [x['message'] for x in logs
if BrowserLogLevel[x['level']] >= threshold
and not any(excl in x['message'] for excl in EXCLUDE_ERRORS)]
assert messages == [], f'Messages with log level {threshold} or above in browser console'


@pytest.mark.parametrize('level,expected',
[
('ALL', True),
('SEVERE', True),
('OFF', False),
])
@pytest.mark.internal

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there another directory we should make for these tests?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could and I debated that, but for now I thought it was premature.

def test_browser_log_level(level, expected):
"""
Self test the logic to determine if browser log matches
"""
assert (BrowserLogLevel.SEVERE >= BrowserLogLevel[level]) == expected