MCPcopy Create free account
hub / github.com/seleniumbase/SeleniumBase / assert_no_js_errors

Method assert_no_js_errors

seleniumbase/fixtures/base_case.py:8753–8859  ·  view source on GitHub ↗

Asserts current URL has no "SEVERE"-level JavaScript errors. Works ONLY on Chromium browsers (Chrome or Edge). Does NOT work on Firefox, IE, Safari, or some other browsers: * See https://github.com/SeleniumHQ/selenium/issues/1161 Based on the following Stack Overf

(self, exclude=[])

Source from the content-addressed store, hash-verified

8751 return True
8752
8753 def assert_no_js_errors(self, exclude=[]):
8754 """Asserts current URL has no "SEVERE"-level JavaScript errors.
8755 Works ONLY on Chromium browsers (Chrome or Edge).
8756 Does NOT work on Firefox, IE, Safari, or some other browsers:
8757 * See https://github.com/SeleniumHQ/selenium/issues/1161
8758 Based on the following Stack Overflow solution:
8759 * https://stackoverflow.com/a/41150512/7058266
8760 @Params
8761 exclude -->
8762 A list of substrings or a single comma-separated string of
8763 substrings for filtering out error URLs that contain them.
8764 URLs that contain any excluded substring will get excluded
8765 from the final errors list that's used with the assertion.
8766 Examples:
8767 self.assert_no_js_errors()
8768 self.assert_no_js_errors(exclude=["/api.", "/analytics."])
8769 self.assert_no_js_errors(exclude="//api.go,/analytics.go")
8770 self.assert_no_js_errors(exclude=["Uncaught SyntaxError"])
8771 self.assert_no_js_errors(exclude=["TypeError", "SyntaxE"]) """
8772 self.__check_scope()
8773 if exclude and not isinstance(exclude, (list, tuple)):
8774 exclude = str(exclude).replace(" ", "").split(",")
8775 time.sleep(0.1) # May take a moment for errors to appear after loads.
8776 try:
8777 browser_logs = self.driver.get_log("browser")
8778 except (ValueError, WebDriverException):
8779 # If unable to get browser logs, skip the assert and return.
8780 return
8781 messenger_library = "//cdnjs.cloudflare.com/ajax/libs/messenger"
8782 underscore_library = "//cdnjs.cloudflare.com/ajax/libs/underscore"
8783 errors = []
8784 for entry in browser_logs:
8785 if entry["level"] == "SEVERE":
8786 if (
8787 messenger_library not in entry["message"]
8788 and underscore_library not in entry["message"]
8789 ):
8790 # Add errors if not caused by SeleniumBase dependencies
8791 if not exclude:
8792 errors.append(entry)
8793 else:
8794 found = False
8795 message = entry["message"]
8796 for substring in exclude:
8797 substring = str(substring)
8798 if (
8799 len(substring) > 0
8800 and substring in message
8801 ):
8802 found = True
8803 break
8804 if not found:
8805 errors.append(entry)
8806 if len(errors) > 0:
8807 for n in range(len(errors)):
8808 f_t_l_r = " - Failed to load resource"
8809 u_c_s_e = " Uncaught SyntaxError: "
8810 u_c_t_e = " Uncaught TypeError: "

Calls 7

__check_scopeMethod · 0.95
get_current_urlMethod · 0.95
failMethod · 0.95
is_chromiumMethod · 0.95
sleepMethod · 0.45

Tested by

no test coverage detected