-
Notifications
You must be signed in to change notification settings - Fork 4
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
+29
−3
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
@@ -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']) | ||
|
||
|
||
EXCLUDE_ERRORS = ( | ||
# Fixed in Foreman 3.7 - https://projects.theforeman.org/issues/36093 | ||
'Scrollbar test exception: TypeError:', | ||
|
@@ -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]') | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there another directory we should make for these tests? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
andOFF
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 asIntFlag
s here 🤷♀️