Skip to content

Commit f8eff16

Browse files
committed
Improve exception-handling when Internet is unreachable
1 parent 1ee9ee9 commit f8eff16

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

seleniumbase/common/exceptions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
""" SeleniumBase Exceptions
22
NoSuchFileException => Called when self.assert_downloaded_file(...) fails.
3+
NotConnectedException => Called when Internet is not reachable when needed.
34
NotUsingChromeException => Used by Chrome-only methods if not using Chrome.
45
NotUsingChromiumException => Used by Chromium-only methods if not Chromium.
56
OutOfScopeException => Used by BaseCase methods when setUp() is skipped.
@@ -13,6 +14,10 @@ class NoSuchFileException(Exception):
1314
pass
1415

1516

17+
class NotConnectedException(Exception):
18+
pass
19+
20+
1621
class NotUsingChromeException(Exception):
1722
pass
1823

seleniumbase/fixtures/base_case.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def test_anything(self):
6161
from seleniumbase.__version__ import __version__
6262
from seleniumbase.common import decorators
6363
from seleniumbase.common.exceptions import (
64+
NotConnectedException,
6465
NotUsingChromeException,
6566
NotUsingChromiumException,
6667
OutOfScopeException,
@@ -249,12 +250,29 @@ def open(self, url):
249250
or "ERR_CONNECTION_CLOSED" in e.msg
250251
or "ERR_CONNECTION_RESET" in e.msg
251252
or "ERR_NAME_NOT_RESOLVED" in e.msg
252-
or "ERR_INTERNET_DISCONNECTED" in e.msg
253253
):
254254
shared_utils.check_if_time_limit_exceeded()
255255
self.__check_browser()
256256
time.sleep(0.8)
257257
self.driver.get(url)
258+
elif (
259+
"ERR_INTERNET_DISCONNECTED" in e.msg
260+
or "neterror?e=dnsNotFound" in e.msg
261+
):
262+
shared_utils.check_if_time_limit_exceeded()
263+
self.__check_browser()
264+
time.sleep(1.05)
265+
try:
266+
self.driver.get(url)
267+
except Exception as e2:
268+
if (
269+
"ERR_INTERNET_DISCONNECTED" in e2.msg
270+
or "neterror?e=dnsNotFound" in e2.msg
271+
):
272+
message = "Internet unreachable!"
273+
raise NotConnectedException(message)
274+
else:
275+
raise
258276
elif "Timed out receiving message from renderer" in e.msg:
259277
page_load_timeout = None
260278
if selenium4_or_newer:

0 commit comments

Comments
 (0)