File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -1514,6 +1514,29 @@ def assert_downloaded_file(self, file):
1514
1514
""" Asserts that the file exists in the Downloads Folder. """
1515
1515
assert os .path .exists (self .get_path_of_downloaded_file (file ))
1516
1516
1517
+ def assert_no_js_errors (self ):
1518
+ """ Asserts that there are no Javascript errors on the page.
1519
+ Only looks for "SEVERE"-level errors.
1520
+ Works best when using Chrome.
1521
+ Does NOT work on Firefox:
1522
+ * See https://github.com/SeleniumHQ/selenium/issues/1161
1523
+ Based on the following Stack Overflow solution:
1524
+ * https://stackoverflow.com/a/41150512/7058266 """
1525
+ try :
1526
+ browser_logs = self .driver .get_log ('browser' )
1527
+ except (ValueError , WebDriverException ):
1528
+ # If unable to get browser logs, skip the assert and return.
1529
+ return
1530
+
1531
+ errors = []
1532
+ for entry in browser_logs :
1533
+ if entry ['level' ] == 'SEVERE' :
1534
+ errors .append (entry )
1535
+ if len (errors ) > 0 :
1536
+ current_url = self .get_current_url ()
1537
+ raise Exception (
1538
+ "Javascript errors found on %s => %s" % (current_url , errors ))
1539
+
1517
1540
def get_google_auth_password (self , totp_key = None ):
1518
1541
""" Returns a time-based one-time password based on the
1519
1542
Google Authenticator password algorithm. Works with Authy.
You can’t perform that action at this time.
0 commit comments