Skip to content

Commit 021bcc0

Browse files
committed
Improve reliability
1 parent faeb571 commit 021bcc0

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

seleniumbase/core/browser_launcher.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ def _set_chrome_options(
431431
chrome_options.add_argument(
432432
"--disable-autofill-keyboard-accessory-view[8]"
433433
)
434+
chrome_options.add_argument("--disable-browser-side-navigation")
434435
chrome_options.add_argument("--disable-translate")
435436
chrome_options.add_argument("--homepage=about:blank")
436437
chrome_options.add_argument("--dns-prefetch-disable")
@@ -1797,6 +1798,7 @@ def get_local_driver(
17971798
edge_options.add_argument(
17981799
"--disable-autofill-keyboard-accessory-view[8]"
17991800
)
1801+
edge_options.add_argument("--disable-browser-side-navigation")
18001802
edge_options.add_argument("--disable-translate")
18011803
if not enable_ws:
18021804
edge_options.add_argument("--disable-web-security")

seleniumbase/fixtures/base_case.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,29 @@ def open(self, url):
200200
):
201201
time.sleep(0.5)
202202
self.driver.get(url)
203+
elif "Timed out receiving message from renderer" in e.msg:
204+
page_load_timeout = None
205+
if selenium4_or_newer:
206+
page_load_timeout = self.driver.timeouts.page_load
207+
else:
208+
if hasattr(settings, "PAGE_LOAD_TIMEOUT"):
209+
page_load_timeout = settings.PAGE_LOAD_TIMEOUT
210+
else:
211+
page_load_timeout = 120
212+
logging.info(
213+
"The page load timed out after %s seconds! Will retry..."
214+
% page_load_timeout
215+
)
216+
try:
217+
self.driver.get(url)
218+
except Exception as e:
219+
if "Timed out receiving message from renderer" in e.msg:
220+
raise Exception(
221+
"Retry of page load timed out after %s seconds!"
222+
% page_load_timeout
223+
)
224+
else:
225+
raise
203226
elif (
204227
"cannot determine loading status" in e.msg
205228
or "unexpected command response" in e.msg
@@ -5475,6 +5498,12 @@ def get_beautiful_soup(self, source=None):
54755498
from bs4 import BeautifulSoup
54765499

54775500
if not source:
5501+
try:
5502+
self.wait_for_element_visible(
5503+
"body", timeout=settings.MINI_TIMEOUT
5504+
)
5505+
except Exception:
5506+
pass
54785507
source = self.get_page_source()
54795508
soup = BeautifulSoup(source, "html.parser")
54805509
return soup
@@ -6277,13 +6306,13 @@ def assert_title(self, title):
62776306
self.assertEqual(expected, actual, error % (expected, actual))
62786307
except Exception:
62796308
self.wait_for_ready_state_complete()
6280-
time.sleep(settings.MINI_TIMEOUT)
6309+
time.sleep(2)
62816310
actual = self.get_page_title().strip()
62826311
try:
62836312
self.assertEqual(expected, actual, error % (expected, actual))
62846313
except Exception:
62856314
self.wait_for_ready_state_complete()
6286-
time.sleep(settings.MINI_TIMEOUT)
6315+
time.sleep(2)
62876316
actual = self.get_page_title().strip()
62886317
self.assertEqual(expected, actual, error % (expected, actual))
62896318
if self.demo_mode and not self.recorder_mode:
@@ -11134,6 +11163,12 @@ def check_window(
1113411163
self.check_window(name="wikipedia_page", level=3)
1113511164
"""
1113611165
self.wait_for_ready_state_complete()
11166+
try:
11167+
self.wait_for_element_visible(
11168+
"body", timeout=settings.MINI_TIMEOUT
11169+
)
11170+
except Exception:
11171+
pass
1113711172
if level == "0":
1113811173
level = 0
1113911174
if level == "1":
@@ -12807,6 +12842,12 @@ def setUp(self, masterqa_mode=False):
1280712842
# Configure the test time limit (if used).
1280812843
self.set_time_limit(self.time_limit)
1280912844

12845+
# Configure the page load timeout
12846+
if hasattr(settings, "PAGE_LOAD_TIMEOUT"):
12847+
self.driver.set_page_load_timeout(settings.PAGE_LOAD_TIMEOUT)
12848+
else:
12849+
self.driver.set_page_load_timeout(120) # Selenium uses 300
12850+
1281012851
# Set the start time for the test (in ms).
1281112852
# Although the pytest clock starts before setUp() begins,
1281212853
# the time-limit clock starts at the end of the setUp() method.

0 commit comments

Comments
 (0)