Skip to content

Commit a84b3b8

Browse files
committed
Improve reliability
1 parent 413b1c8 commit a84b3b8

File tree

1 file changed

+43
-4
lines changed

1 file changed

+43
-4
lines changed

seleniumbase/fixtures/base_case.py

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ def open(self, url):
166166
"""Navigates the current browser window to the specified page."""
167167
self.__check_scope()
168168
self.__check_browser()
169+
if self.__needs_minimum_wait():
170+
time.sleep(0.01)
169171
pre_action_url = None
170172
try:
171173
pre_action_url = self.driver.current_url
@@ -238,6 +240,8 @@ def open(self, url):
238240
time.sleep(0.1) # Make sure load happens
239241
if settings.WAIT_FOR_RSC_ON_PAGE_LOADS:
240242
self.wait_for_ready_state_complete()
243+
if self.__needs_minimum_wait():
244+
time.sleep(0.03) # Force a minimum wait, even if skipping waits.
241245
self.__demo_mode_pause_if_active()
242246

243247
def get(self, url):
@@ -461,12 +465,16 @@ def click(
461465
self.wait_for_ready_state_complete()
462466
except Exception:
463467
pass
468+
if self.__needs_minimum_wait():
469+
time.sleep(0.02)
464470
else:
465471
# A smaller subset of self.wait_for_ready_state_complete()
466472
try:
467473
self.wait_for_angularjs(timeout=settings.MINI_TIMEOUT)
468474
except Exception:
469475
pass
476+
if self.__needs_minimum_wait():
477+
time.sleep(0.01)
470478
try:
471479
if self.driver.current_url != pre_action_url:
472480
self.__ad_block_as_needed()
@@ -476,6 +484,8 @@ def click(
476484
self.wait_for_ready_state_complete()
477485
except Exception:
478486
pass
487+
if self.__needs_minimum_wait():
488+
time.sleep(0.02)
479489
if self.demo_mode:
480490
if self.driver.current_url != pre_action_url:
481491
self.__demo_mode_pause_if_active()
@@ -923,6 +933,8 @@ def get_origin(self):
923933

924934
def get_page_source(self):
925935
self.wait_for_ready_state_complete()
936+
if self.__needs_minimum_wait:
937+
time.sleep(0.02)
926938
return self.driver.page_source
927939

928940
def get_page_title(self):
@@ -2106,7 +2118,7 @@ def switch_to_frame_of_element(self, selector, by="css selector"):
21062118
element is in a single-nested iframe) and returns the iframe name.
21072119
If element is not in an iframe, returns None, and nothing happens.
21082120
May not work if multiple iframes are nested within each other."""
2109-
self.__check_scope()
2121+
self.wait_for_ready_state_complete()
21102122
selector, by = self.__recalculate_selector(selector, by)
21112123
if self.is_element_present(selector, by=by):
21122124
return None
@@ -2890,7 +2902,11 @@ def switch_to_frame(self, frame, timeout=None):
28902902
action = ["sw_fr", frame, origin, time_stamp]
28912903
self.__extra_actions.append(action)
28922904
return
2905+
self.wait_for_ready_state_complete()
2906+
if self.__needs_minimum_wait():
2907+
time.sleep(0.02)
28932908
page_actions.switch_to_frame(self.driver, frame, timeout)
2909+
self.wait_for_ready_state_complete()
28942910

28952911
def switch_to_default_content(self):
28962912
"""Brings driver control outside the current iframe.
@@ -3701,6 +3717,16 @@ def delete_saved_cookies(self, name="cookies.txt"):
37013717
if cookies_file_path.endswith(".txt"):
37023718
os.remove(cookies_file_path)
37033719

3720+
def __needs_minimum_wait(self):
3721+
if (
3722+
self.page_load_strategy == "none"
3723+
and hasattr(settings, "SKIP_JS_WAITS")
3724+
and settings.SKIP_JS_WAITS
3725+
):
3726+
return True
3727+
else:
3728+
return False
3729+
37043730
def __ad_block_as_needed(self):
37053731
"""This is an internal method for handling ad-blocking.
37063732
Use "pytest --ad-block" to enable this during tests.
@@ -3730,6 +3756,13 @@ def wait_for_ready_state_complete(self, timeout=None):
37303756
self.assert_no_js_errors()
37313757
self.__ad_block_as_needed()
37323758
self.__disable_beforeunload_as_needed()
3759+
if (
3760+
self.undetectable
3761+
and self.page_load_strategy == "none"
3762+
and hasattr(settings, "SKIP_JS_WAITS")
3763+
and settings.SKIP_JS_WAITS
3764+
):
3765+
time.sleep(0.03)
37333766
return True
37343767

37353768
def wait_for_angularjs(self, timeout=None, **kwargs):
@@ -5666,13 +5699,14 @@ def get_unique_links(self):
56665699
Page links include those obtained from:
56675700
"a"->"href", "img"->"src", "link"->"href", and "script"->"src".
56685701
"""
5669-
self.__check_scope()
5670-
if settings.SKIP_JS_WAITS and self.page_load_strategy == "none":
5671-
time.sleep(0.16)
5702+
self.wait_for_ready_state_complete()
56725703
try:
5704+
self.wait_for_element_present("body", timeout=1.5)
56735705
self.wait_for_element_visible("body", timeout=1.5)
56745706
except Exception:
56755707
pass
5708+
if self.__needs_minimum_wait():
5709+
time.sleep(0.25)
56765710
soup = self.get_beautiful_soup(self.get_page_source())
56775711
page_url = self.get_current_url()
56785712
links = page_utils._get_unique_links(page_url, soup)
@@ -11520,6 +11554,8 @@ def check_window(
1152011554
self.check_window(name="wikipedia_page", level=3)
1152111555
"""
1152211556
self.wait_for_ready_state_complete()
11557+
if self.__needs_minimum_wait():
11558+
time.sleep(0.02) # Force a minimum wait, even if skipping waits.
1152311559
try:
1152411560
self.wait_for_element_visible(
1152511561
"body", timeout=settings.MINI_TIMEOUT
@@ -12209,6 +12245,9 @@ def __click_with_offset(
1220912245
):
1221012246
from selenium.webdriver.common.action_chains import ActionChains
1221112247

12248+
self.wait_for_ready_state_complete()
12249+
if self.__needs_minimum_wait():
12250+
time.sleep(0.02) # Force a minimum wait, even if skipping waits.
1221212251
if not timeout:
1221312252
timeout = settings.SMALL_TIMEOUT
1221412253
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:

0 commit comments

Comments
 (0)