@@ -209,7 +209,7 @@ def test_example(self):
209
209
def open(self, url):
210
210
"""Navigates the current browser window to the specified page."""
211
211
self.__check_scope()
212
- self.__check_browser ()
212
+ self._check_browser ()
213
213
if self.__needs_minimum_wait():
214
214
time.sleep(0.03)
215
215
if self.undetectable:
@@ -255,7 +255,7 @@ def open(self, url):
255
255
or "ERR_NAME_NOT_RESOLVED" in e.msg
256
256
):
257
257
shared_utils.check_if_time_limit_exceeded()
258
- self.__check_browser ()
258
+ self._check_browser ()
259
259
time.sleep(0.8)
260
260
self.driver.get(url)
261
261
elif (
@@ -264,7 +264,7 @@ def open(self, url):
264
264
or "ERR_PROXY_CONNECTION_FAILED" in e.msg
265
265
):
266
266
shared_utils.check_if_time_limit_exceeded()
267
- self.__check_browser ()
267
+ self._check_browser ()
268
268
time.sleep(1.05)
269
269
try:
270
270
self.driver.get(url)
@@ -3205,17 +3205,17 @@ def open_html_file(self, html_file):
3205
3205
3206
3206
def execute_script(self, script, *args, **kwargs):
3207
3207
self.__check_scope()
3208
- self.__check_browser ()
3208
+ self._check_browser ()
3209
3209
return self.driver.execute_script(script, *args, **kwargs)
3210
3210
3211
3211
def execute_cdp_cmd(self, script, *args, **kwargs):
3212
3212
self.__check_scope()
3213
- self.__check_browser ()
3213
+ self._check_browser ()
3214
3214
return self.driver.execute_cdp_cmd(script, *args, **kwargs)
3215
3215
3216
3216
def execute_async_script(self, script, timeout=None):
3217
3217
self.__check_scope()
3218
- self.__check_browser ()
3218
+ self._check_browser ()
3219
3219
if not timeout:
3220
3220
timeout = settings.EXTREME_TIMEOUT
3221
3221
return js_utils.execute_async_script(self.driver, script, timeout)
@@ -3225,26 +3225,26 @@ def safe_execute_script(self, script, *args, **kwargs):
3225
3225
it's important that the jQuery library has been loaded first.
3226
3226
This method will load jQuery if it wasn't already loaded."""
3227
3227
self.__check_scope()
3228
- self.__check_browser ()
3228
+ self._check_browser ()
3229
3229
if not js_utils.is_jquery_activated(self.driver):
3230
3230
self.activate_jquery()
3231
3231
return self.driver.execute_script(script, *args, **kwargs)
3232
3232
3233
3233
def set_window_rect(self, x, y, width, height):
3234
3234
self.__check_scope()
3235
- self.__check_browser ()
3235
+ self._check_browser ()
3236
3236
self.driver.set_window_rect(x, y, width, height)
3237
3237
self.__demo_mode_pause_if_active()
3238
3238
3239
3239
def set_window_size(self, width, height):
3240
3240
self.__check_scope()
3241
- self.__check_browser ()
3241
+ self._check_browser ()
3242
3242
self.driver.set_window_size(width, height)
3243
3243
self.__demo_mode_pause_if_active()
3244
3244
3245
3245
def maximize_window(self):
3246
3246
self.__check_scope()
3247
- self.__check_browser ()
3247
+ self._check_browser ()
3248
3248
self.driver.maximize_window()
3249
3249
self.__demo_mode_pause_if_active()
3250
3250
@@ -4208,7 +4208,7 @@ def wait_for_ready_state_complete(self, timeout=None):
4208
4208
"""Waits for the "readyState" of the page to be "complete".
4209
4209
Returns True when the method completes."""
4210
4210
self.__check_scope()
4211
- self.__check_browser ()
4211
+ self._check_browser ()
4212
4212
if not timeout:
4213
4213
timeout = settings.EXTREME_TIMEOUT
4214
4214
if self.timeout_multiplier and timeout == settings.EXTREME_TIMEOUT:
@@ -6191,7 +6191,7 @@ def disable_beforeunload(self):
6191
6191
on Chromium browsers (Chrome or Edge).
6192
6192
SB already sets "dom.disable_beforeunload" for Firefox options."""
6193
6193
self.__check_scope()
6194
- self.__check_browser ()
6194
+ self._check_browser ()
6195
6195
if (
6196
6196
self.is_chromium()
6197
6197
and self.driver.current_url.startswith("http")
@@ -8468,6 +8468,17 @@ def block_ads(self):
8468
8468
"""Same as self.ad_block()"""
8469
8469
self.ad_block()
8470
8470
8471
+ def _check_browser(self):
8472
+ """This method raises an exception if the active window is closed.
8473
+ (This provides a much cleaner exception message in this situation.)"""
8474
+ active_window = None
8475
+ try:
8476
+ active_window = self.driver.current_window_handle # Fails if None
8477
+ except Exception:
8478
+ pass
8479
+ if not active_window:
8480
+ raise NoSuchWindowException("Active window was already closed!")
8481
+
8471
8482
def _print(self, msg):
8472
8483
"""Same as Python's print(), but also prints during multithreaded runs.
8473
8484
Normally, Python's print() command won't print for multithreaded tests.
@@ -8490,32 +8501,32 @@ def _print(self, msg):
8490
8501
8491
8502
def add_css_link(self, css_link):
8492
8503
self.__check_scope()
8493
- self.__check_browser ()
8504
+ self._check_browser ()
8494
8505
js_utils.add_css_link(self.driver, css_link)
8495
8506
8496
8507
def add_js_link(self, js_link):
8497
8508
self.__check_scope()
8498
- self.__check_browser ()
8509
+ self._check_browser ()
8499
8510
js_utils.add_js_link(self.driver, js_link)
8500
8511
8501
8512
def add_css_style(self, css_style):
8502
8513
self.__check_scope()
8503
- self.__check_browser ()
8514
+ self._check_browser ()
8504
8515
js_utils.add_css_style(self.driver, css_style)
8505
8516
8506
8517
def add_js_code_from_link(self, js_link):
8507
8518
self.__check_scope()
8508
- self.__check_browser ()
8519
+ self._check_browser ()
8509
8520
js_utils.add_js_code_from_link(self.driver, js_link)
8510
8521
8511
8522
def add_js_code(self, js_code):
8512
8523
self.__check_scope()
8513
- self.__check_browser ()
8524
+ self._check_browser ()
8514
8525
js_utils.add_js_code(self.driver, js_code)
8515
8526
8516
8527
def add_meta_tag(self, http_equiv=None, content=None):
8517
8528
self.__check_scope()
8518
- self.__check_browser ()
8529
+ self._check_browser ()
8519
8530
js_utils.add_meta_tag(
8520
8531
self.driver, http_equiv=http_equiv, content=content
8521
8532
)
@@ -8524,7 +8535,7 @@ def add_meta_tag(self, http_equiv=None, content=None):
8524
8535
8525
8536
def activate_messenger(self):
8526
8537
self.__check_scope()
8527
- self.__check_browser ()
8538
+ self._check_browser ()
8528
8539
js_utils.activate_messenger(self.driver)
8529
8540
self.wait_for_ready_state_complete()
8530
8541
@@ -8537,7 +8548,7 @@ def set_messenger_theme(
8537
8548
"bottom_left", "bottom_center", "bottom_right"]
8538
8549
max_messages: The limit of concurrent messages to display."""
8539
8550
self.__check_scope()
8540
- self.__check_browser ()
8551
+ self._check_browser ()
8541
8552
if not theme:
8542
8553
theme = "default" # "flat"
8543
8554
if not location:
@@ -8564,7 +8575,7 @@ def post_message(self, message, duration=None, pause=True, style="info"):
8564
8575
You can also post messages by using =>
8565
8576
self.execute_script('Messenger().post("My Message")') """
8566
8577
self.__check_scope()
8567
- self.__check_browser ()
8578
+ self._check_browser ()
8568
8579
if style not in ["info", "success", "error"]:
8569
8580
style = "info"
8570
8581
if not duration:
@@ -8601,7 +8612,7 @@ def post_success_message(self, message, duration=None, pause=True):
8601
8612
duration: The time until the message vanishes. (Default: 2.55s)
8602
8613
pause: If True, the program waits until the message completes."""
8603
8614
self.__check_scope()
8604
- self.__check_browser ()
8615
+ self._check_browser ()
8605
8616
if not duration:
8606
8617
if not self.message_duration:
8607
8618
duration = settings.DEFAULT_MESSAGE_DURATION
@@ -8629,7 +8640,7 @@ def post_error_message(self, message, duration=None, pause=True):
8629
8640
duration: The time until the message vanishes. (Default: 2.55s)
8630
8641
pause: If True, the program waits until the message completes."""
8631
8642
self.__check_scope()
8632
- self.__check_browser ()
8643
+ self._check_browser ()
8633
8644
if not duration:
8634
8645
if not self.message_duration:
8635
8646
duration = settings.DEFAULT_MESSAGE_DURATION
@@ -9781,7 +9792,7 @@ def quit_extra_driver(self, driver=None):
9781
9792
if driver == self.driver:
9782
9793
self.switch_to_default_driver()
9783
9794
try:
9784
- self.__check_browser ()
9795
+ self._check_browser ()
9785
9796
except Exception:
9786
9797
self._default_driver = self._drivers_list[-1]
9787
9798
self.switch_to_default_driver()
@@ -10231,18 +10242,6 @@ def __check_scope(self):
10231
10242
10232
10243
############
10233
10244
10234
- def __check_browser(self):
10235
- """This method raises an exception if the window was already closed."""
10236
- active_window = None
10237
- try:
10238
- active_window = self.driver.current_window_handle # Fails if None
10239
- except Exception:
10240
- pass
10241
- if not active_window:
10242
- raise NoSuchWindowException("Active window was already closed!")
10243
-
10244
- ############
10245
-
10246
10245
def __get_exception_message(self):
10247
10246
"""This method extracts the message from an exception if there
10248
10247
was an exception that occurred during the test, assuming
@@ -12298,7 +12297,7 @@ def export_tour(self, name=None, filename="my_tour.js", url=None):
12298
12297
def activate_jquery_confirm(self):
12299
12298
"""See https://craftpip.github.io/jquery-confirm/ for usage."""
12300
12299
self.__check_scope()
12301
- self.__check_browser ()
12300
+ self._check_browser ()
12302
12301
js_utils.activate_jquery_confirm(self.driver)
12303
12302
self.wait_for_ready_state_complete()
12304
12303
0 commit comments