Skip to content

Commit c8091fb

Browse files
committed
Improve the script that detects and displays JS errors
1 parent 10461d4 commit c8091fb

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

seleniumbase/fixtures/base_case.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5005,18 +5005,33 @@ def assert_no_js_errors(self):
50055005
except (ValueError, WebDriverException):
50065006
# If unable to get browser logs, skip the assert and return.
50075007
return
5008-
50095008
messenger_library = "//cdnjs.cloudflare.com/ajax/libs/messenger"
5009+
underscore_library = "//cdnjs.cloudflare.com/ajax/libs/underscore"
50105010
errors = []
50115011
for entry in browser_logs:
50125012
if entry["level"] == "SEVERE":
5013-
if messenger_library not in entry["message"]:
5013+
if (
5014+
messenger_library not in entry["message"]
5015+
and underscore_library not in entry["message"]
5016+
):
50145017
# Add errors if not caused by SeleniumBase dependencies
50155018
errors.append(entry)
50165019
if len(errors) > 0:
5020+
for n in range(len(errors)):
5021+
f_t_l_r = " - Failed to load resource"
5022+
u_c_t_e = " Uncaught TypeError: "
5023+
if f_t_l_r in errors[n]["message"]:
5024+
url = errors[n]["message"].split(f_t_l_r)[0]
5025+
errors[n] = {"Error 404 (broken link)": url}
5026+
elif u_c_t_e in errors[n]["message"]:
5027+
url = errors[n]["message"].split(u_c_t_e)[0]
5028+
error = errors[n]["message"].split(u_c_t_e)[1]
5029+
errors[n] = {"Uncaught TypeError (%s)" % error: url}
5030+
er_str = str(errors)
5031+
er_str = er_str.replace("[{", "[\n{").replace("}, {", "},\n{")
50175032
current_url = self.get_current_url()
50185033
raise Exception(
5019-
"JavaScript errors found on %s => %s" % (current_url, errors)
5034+
"JavaScript errors found on %s => %s" % (current_url, er_str)
50205035
)
50215036
if self.demo_mode:
50225037
if self.browser == "chrome" or self.browser == "edge":

0 commit comments

Comments
 (0)