@@ -97,6 +97,14 @@ def __init__(self, *args, **kwargs):
97
97
98
98
def open (self , url ):
99
99
""" Navigates the current browser window to the specified page. """
100
+ if type (url ) is str :
101
+ url = url .strip () # Remove leading and trailing whitespace
102
+ if (type (url ) is not str ) or not self .__looks_like_a_page_url (url ):
103
+ # url should start with one of the following:
104
+ # "http:", "https:", "://", "data:", "file:",
105
+ # "about:", "chrome:", "opera:", or "edge:".
106
+ msg = 'Did you forget to prefix your URL with "http:" or "https:"?'
107
+ raise Exception ('Invalid URL: "%s"\n %s' % (url , msg ))
100
108
self .__last_page_load_url = None
101
109
js_utils .clear_out_console_logs (self .driver )
102
110
if url .startswith ("://" ):
@@ -5797,9 +5805,10 @@ def __looks_like_a_page_url(self, url):
5797
5805
navigate to the page if a URL is detected, but will instead call
5798
5806
self.get_element(URL_AS_A_SELECTOR) if the input in not a URL. """
5799
5807
if (url .startswith ("http:" ) or url .startswith ("https:" ) or (
5800
- url .startswith ("://" ) or url .startswith ("data:" ) or (
5801
- url .startswith ("about:" ) or url .startswith ("chrome:" ) or (
5802
- url .startswith ("file:" ))))):
5808
+ url .startswith ("://" ) or url .startswith ("chrome:" ) or (
5809
+ url .startswith ("about:" ) or url .startswith ("data:" ) or (
5810
+ url .startswith ("file:" ) or url .startswith ("edge:" ) or (
5811
+ url .startswith ("opera:" )))))):
5803
5812
return True
5804
5813
else :
5805
5814
return False
@@ -6367,6 +6376,34 @@ def tearDown(self):
6367
6376
You'll need to add the following line to the subclass's tearDown():
6368
6377
super(SubClassOfBaseCase, self).tearDown()
6369
6378
"""
6379
+ try :
6380
+ with_selenium = self .with_selenium
6381
+ except Exception :
6382
+ sub_class_name = str (
6383
+ self .__class__ .__bases__ [0 ]).split ('.' )[- 1 ].split ("'" )[0 ]
6384
+ sub_file_name = str (self .__class__ .__bases__ [0 ]).split ('.' )[- 2 ]
6385
+ sub_file_name = sub_file_name + ".py"
6386
+ class_name = str (self .__class__ ).split ('.' )[- 1 ].split ("'" )[0 ]
6387
+ file_name = str (self .__class__ ).split ('.' )[- 2 ] + ".py"
6388
+ class_name_used = sub_class_name
6389
+ file_name_used = sub_file_name
6390
+ if sub_class_name == "BaseCase" :
6391
+ class_name_used = class_name
6392
+ file_name_used = file_name
6393
+ fix_setup = "super(%s, self).setUp()" % class_name_used
6394
+ fix_teardown = "super(%s, self).tearDown()" % class_name_used
6395
+ message = ("You're overriding SeleniumBase's BaseCase setUp() "
6396
+ "method with your own setUp() method, which breaks "
6397
+ "SeleniumBase. You can fix this by going to your "
6398
+ "%s class located in your %s file and adding the "
6399
+ "following line of code AT THE BEGINNING of your "
6400
+ "setUp() method:\n %s\n \n Also make sure "
6401
+ "you have added the following line of code AT THE "
6402
+ "END of your tearDown() method:\n %s\n "
6403
+ % (class_name_used , file_name_used ,
6404
+ fix_setup , fix_teardown ))
6405
+ raise Exception (message )
6406
+ # *** Start tearDown() officially ***
6370
6407
self .__slow_mode_pause_if_active ()
6371
6408
has_exception = self .__has_exception ()
6372
6409
if self .__deferred_assert_failures :
@@ -6381,33 +6418,6 @@ def tearDown(self):
6381
6418
if self .is_pytest :
6382
6419
# pytest-specific code
6383
6420
test_id = self .__get_test_id ()
6384
- try :
6385
- with_selenium = self .with_selenium
6386
- except Exception :
6387
- sub_class_name = str (
6388
- self .__class__ .__bases__ [0 ]).split ('.' )[- 1 ].split ("'" )[0 ]
6389
- sub_file_name = str (self .__class__ .__bases__ [0 ]).split ('.' )[- 2 ]
6390
- sub_file_name = sub_file_name + ".py"
6391
- class_name = str (self .__class__ ).split ('.' )[- 1 ].split ("'" )[0 ]
6392
- file_name = str (self .__class__ ).split ('.' )[- 2 ] + ".py"
6393
- class_name_used = sub_class_name
6394
- file_name_used = sub_file_name
6395
- if sub_class_name == "BaseCase" :
6396
- class_name_used = class_name
6397
- file_name_used = file_name
6398
- fix_setup = "super(%s, self).setUp()" % class_name_used
6399
- fix_teardown = "super(%s, self).tearDown()" % class_name_used
6400
- message = ("You're overriding SeleniumBase's BaseCase setUp() "
6401
- "method with your own setUp() method, which breaks "
6402
- "SeleniumBase. You can fix this by going to your "
6403
- "%s class located in your %s file and adding the "
6404
- "following line of code AT THE BEGINNING of your "
6405
- "setUp() method:\n %s\n \n Also make sure "
6406
- "you have added the following line of code AT THE "
6407
- "END of your tearDown() method:\n %s\n "
6408
- % (class_name_used , file_name_used ,
6409
- fix_setup , fix_teardown ))
6410
- raise Exception (message )
6411
6421
if with_selenium :
6412
6422
# Save a screenshot if logging is on when an exception occurs
6413
6423
if has_exception :
0 commit comments