Skip to content

Commit 1d09bf3

Browse files
authored
Merge pull request #1555 from seleniumbase/customizing-assert-no-js-errors
Add arg for excluding URLs from assert_no_js_errors()
2 parents 4f20c34 + 41af7ef commit 1d09bf3

File tree

6 files changed

+56
-16
lines changed

6 files changed

+56
-16
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
<meta property="og:image" content="https://seleniumbase.github.io/cdn/img/mac_sb_logo_5b.png" />
66
<link rel="icon" href="https://seleniumbase.github.io/img/logo3b.png" />
77

8-
<p align="center"><a href="https://github.com/seleniumbase/SeleniumBase/"><img src="https://seleniumbase.github.io/cdn/img/sb_media_logo_t3.png" alt="SeleniumBase" title="SeleniumBase" width="442" /></a></p>
8+
<h1>SeleniumBase</h1>
99

10-
<p align="center"><b>SeleniumBase</b> is a <a href="https://www.selenium.dev/documentation/webdriver/" target="_blank">WebDriver</a> framework for <b>Python</b> and <b><a href="https://docs.pytest.org/en/latest/how-to/usage.html">pytest</a></b>.</p>
10+
<p align="center"><a href="https://github.com/seleniumbase/SeleniumBase/"><img src="https://seleniumbase.github.io/cdn/img/logo_base_3.png" alt="SeleniumBase" title="SeleniumBase" width="234" /></a></p>
11+
12+
<h3 align="center"><b>All-in-one test automation framework</b></h3>
1113

1214
<p align="center"><a href="https://pypi.python.org/pypi/seleniumbase" target="_blank"><img src="https://img.shields.io/pypi/v/seleniumbase.svg?color=3399EE" alt="PyPI version" /></a> <a href="https://github.com/seleniumbase/SeleniumBase/releases" target="_blank"><img src="https://img.shields.io/github/v/release/seleniumbase/SeleniumBase.svg?color=22AAEE" alt="GitHub version" /></a> <a href="https://seleniumbase.io"><img src="https://img.shields.io/badge/docs-seleniumbase.io-11BBAA.svg" alt="SeleniumBase Docs" /></a> <a href="https://github.com/seleniumbase/SeleniumBase/actions" target="_blank"><img src="https://github.com/seleniumbase/SeleniumBase/workflows/CI%20build/badge.svg" alt="SeleniumBase GitHub Actions" /></a> <a href="https://gitter.im/seleniumbase/SeleniumBase" target="_blank"><img src="https://badges.gitter.im/seleniumbase/SeleniumBase.svg" alt="SeleniumBase" /></a></p>
1315

@@ -107,7 +109,7 @@ pytest test_swag_labs.py --demo
107109

108110
<p>💡 SeleniumBase gives you clean error output when a test fails. With raw Selenium, error messages can get very messy.</p>
109111

110-
<p>💡 SeleniumBase gives you the option to generate a dashboard and reports for tests. It also saves screenshots from failing tests to the <code>./latest_logs/</code> folder. Raw Selenium does not have these options out-of-the-box.</p>
112+
<p>💡 SeleniumBase gives you the option to generate a dashboard and reports for tests. It also saves screenshots from failing tests to the <code>./latest_logs/</code> folder. Raw <a href="https://www.selenium.dev/documentation/webdriver/" target="_blank">Selenium</a> does not have these options out-of-the-box.</p>
111113

112114
<p>💡 SeleniumBase includes desktop GUI apps for running tests, such as <b>SeleniumBase Commander</b> for <code>pytest</code>, and <b>SeleniumBase Behave GUI.</b></p>
113115

@@ -381,7 +383,7 @@ self.assert_no_js_errors() # Verify there are no JS errors.
381383
<a id="fun_facts"></a>
382384
<h2><img src="https://seleniumbase.github.io/img/logo3b.png" title="SeleniumBase" width="32" /> Fun Facts / Learn More:</h2>
383385
384-
<p>✅ SeleniumBase automatically handles common WebDriver actions such as launching web browsers before tests, saving screenshots during failures, and closing web browsers after tests.</p>
386+
<p>✅ SeleniumBase automatically handles common <a href="https://www.selenium.dev/documentation/webdriver/" target="_blank">WebDriver</a> actions such as launching web browsers before tests, saving screenshots during failures, and closing web browsers after tests.</p>
385387
386388
<p>✅ SeleniumBase lets you <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/customizing_test_runs.md">customize test runs from the command-line</a>.</p>
387389
@@ -898,7 +900,7 @@ self.click("div#my_id")
898900
self.type("input#id_value", "2012")
899901
```
900902
901-
You can also use <code>self.add_text()</code> or the WebDriver <code>.send_keys()</code> command, but those won't clear the text box first if there's already text inside.
903+
You can also use <code>self.add_text()</code> or the <a href="https://www.selenium.dev/documentation/webdriver/" target="_blank">WebDriver</a> <code>.send_keys()</code> command, but those won't clear the text box first if there's already text inside.
902904
903905
🔵 Getting the text from an element on a page:
904906
@@ -1124,9 +1126,9 @@ class MyTestClass(BaseCase):
11241126
<code>deferred_assert_element()</code> and <code>deferred_assert_text()</code> will save any exceptions that would be raised.
11251127
To flush out all the failed deferred asserts into a single exception, make sure to call <code>self.process_deferred_asserts()</code> at the end of your test method. If your test hits multiple pages, you can call <code>self.process_deferred_asserts()</code> before navigating to a new page so that the screenshot from your log files matches the URL where the deferred asserts were made.
11261128
1127-
🔵 Accessing Raw WebDriver:
1129+
🔵 Accessing Raw <a href="https://www.selenium.dev/documentation/webdriver/" target="_blank">WebDriver</a>:
11281130
1129-
<p>If you need access to any commands that come with standard WebDriver, you can call them directly like this:</p>
1131+
<p>If you need access to any commands that come with standard <a href="https://www.selenium.dev/documentation/webdriver/" target="_blank">WebDriver</a>, you can call them directly like this:</p>
11301132
11311133
```python
11321134
self.driver.delete_all_cookies()

help_docs/method_summary.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ self.assert_title(title)
460460

461461
self.assert_title_contains(substring)
462462

463-
self.assert_no_js_errors()
463+
self.assert_no_js_errors(exclude=[])
464464

465465
self.inspect_html()
466466

seleniumbase/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "4.6.3"
2+
__version__ = "4.6.4"

seleniumbase/console_scripts/sb_behave_gui.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,11 @@ def create_tkinter_gui(tests, command_string):
243243
tk.Label(root, text="").pack()
244244
run_display = (
245245
"Select from %s tests: "
246-
"(If NO TESTS are selected, then ALL TESTS will be run)"
246+
"(If NO TESTS are selected, then ALL TESTS will run)"
247247
% len(tests)
248248
)
249249
if len(tests) == 1:
250-
run_display = "Only ONE TEST was found: (Will be run automatically)"
250+
run_display = "Only ONE TEST was found: (Will run automatically)"
251251
tk.Label(root, text=run_display, fg="blue").pack()
252252
text_area = ScrolledText(
253253
root, width=100, height=12, wrap="word", state=tk.DISABLED

seleniumbase/console_scripts/sb_commander.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,11 @@ def create_tkinter_gui(tests, command_string):
243243
tk.Label(root, text="").pack()
244244
run_display = (
245245
"Select from %s tests: "
246-
"(If NO TESTS are selected, then ALL TESTS will be run)"
246+
"(If NO TESTS are selected, then ALL TESTS will run)"
247247
% len(tests)
248248
)
249249
if len(tests) == 1:
250-
run_display = "Only ONE TEST was found: (Will be run automatically)"
250+
run_display = "Only ONE TEST was found: (Will run automatically)"
251251
tk.Label(root, text=run_display, fg="blue").pack()
252252
text_area = ScrolledText(
253253
root, width=100, height=12, wrap="word", state=tk.DISABLED

seleniumbase/fixtures/base_case.py

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6521,15 +6521,31 @@ def assert_title_contains(self, substring):
65216521
self.__extra_actions.append(action)
65226522
return True
65236523

6524-
def assert_no_js_errors(self):
6525-
"""Asserts that there are no JavaScript "SEVERE"-level page errors.
6524+
def assert_no_js_errors(self, exclude=[]):
6525+
"""Asserts current URL has no "SEVERE"-level JavaScript errors.
65266526
Works ONLY on Chromium browsers (Chrome or Edge).
65276527
Does NOT work on Firefox, IE, Safari, or some other browsers:
65286528
* See https://github.com/SeleniumHQ/selenium/issues/1161
65296529
Based on the following Stack Overflow solution:
65306530
* https://stackoverflow.com/a/41150512/7058266
6531+
@Params
6532+
exclude -->
6533+
A list of substrings or a single comma-separated string of
6534+
substrings for filtering out error URLs that contain them.
6535+
URLs that contain any excluded substring will get excluded
6536+
from the final errors list that's used with the assertion.
6537+
Examples:
6538+
self.assert_no_js_errors()
6539+
self.assert_no_js_errors(exclude=["/api.", "/analytics."])
6540+
self.assert_no_js_errors(exclude="//api.go,/analytics.go")
65316541
"""
65326542
self.__check_scope()
6543+
if (
6544+
exclude
6545+
and not type(exclude) is list
6546+
and not type(exclude) is tuple
6547+
):
6548+
exclude = str(exclude).replace(" ", "").split(",")
65336549
time.sleep(0.1) # May take a moment for errors to appear after loads.
65346550
try:
65356551
browser_logs = self.driver.get_log("browser")
@@ -6546,7 +6562,29 @@ def assert_no_js_errors(self):
65466562
and underscore_library not in entry["message"]
65476563
):
65486564
# Add errors if not caused by SeleniumBase dependencies
6549-
errors.append(entry)
6565+
if not exclude:
6566+
errors.append(entry)
6567+
else:
6568+
found = False
6569+
message = entry["message"]
6570+
if message.count(" - Failed to load resource") == 1:
6571+
message = message.split(
6572+
" - Failed to load resource"
6573+
)[0]
6574+
elif message.count(" Uncaught TypeError: ") == 1:
6575+
message = message.split(
6576+
" Uncaught TypeError: "
6577+
)[0]
6578+
for substring in exclude:
6579+
substring = str(substring)
6580+
if (
6581+
len(substring) > 0
6582+
and substring in message
6583+
):
6584+
found = True
6585+
break
6586+
if not found:
6587+
errors.append(entry)
65506588
if len(errors) > 0:
65516589
for n in range(len(errors)):
65526590
f_t_l_r = " - Failed to load resource"

0 commit comments

Comments
 (0)