Improve exception-handling when Internet is unreachable
This commit is contained in:
parent
1ee9ee9a32
commit
f8eff16e9d
|
@ -1,5 +1,6 @@
|
|||
""" SeleniumBase Exceptions
|
||||
NoSuchFileException => Called when self.assert_downloaded_file(...) fails.
|
||||
NotConnectedException => Called when Internet is not reachable when needed.
|
||||
NotUsingChromeException => Used by Chrome-only methods if not using Chrome.
|
||||
NotUsingChromiumException => Used by Chromium-only methods if not Chromium.
|
||||
OutOfScopeException => Used by BaseCase methods when setUp() is skipped.
|
||||
|
@ -13,6 +14,10 @@ class NoSuchFileException(Exception):
|
|||
pass
|
||||
|
||||
|
||||
class NotConnectedException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class NotUsingChromeException(Exception):
|
||||
pass
|
||||
|
||||
|
|
|
@ -61,6 +61,7 @@ from seleniumbase import config as sb_config
|
|||
from seleniumbase.__version__ import __version__
|
||||
from seleniumbase.common import decorators
|
||||
from seleniumbase.common.exceptions import (
|
||||
NotConnectedException,
|
||||
NotUsingChromeException,
|
||||
NotUsingChromiumException,
|
||||
OutOfScopeException,
|
||||
|
@ -249,12 +250,29 @@ class BaseCase(unittest.TestCase):
|
|||
or "ERR_CONNECTION_CLOSED" in e.msg
|
||||
or "ERR_CONNECTION_RESET" in e.msg
|
||||
or "ERR_NAME_NOT_RESOLVED" in e.msg
|
||||
or "ERR_INTERNET_DISCONNECTED" in e.msg
|
||||
):
|
||||
shared_utils.check_if_time_limit_exceeded()
|
||||
self.__check_browser()
|
||||
time.sleep(0.8)
|
||||
self.driver.get(url)
|
||||
elif (
|
||||
"ERR_INTERNET_DISCONNECTED" in e.msg
|
||||
or "neterror?e=dnsNotFound" in e.msg
|
||||
):
|
||||
shared_utils.check_if_time_limit_exceeded()
|
||||
self.__check_browser()
|
||||
time.sleep(1.05)
|
||||
try:
|
||||
self.driver.get(url)
|
||||
except Exception as e2:
|
||||
if (
|
||||
"ERR_INTERNET_DISCONNECTED" in e2.msg
|
||||
or "neterror?e=dnsNotFound" in e2.msg
|
||||
):
|
||||
message = "Internet unreachable!"
|
||||
raise NotConnectedException(message)
|
||||
else:
|
||||
raise
|
||||
elif "Timed out receiving message from renderer" in e.msg:
|
||||
page_load_timeout = None
|
||||
if selenium4_or_newer:
|
||||
|
|
Loading…
Reference in New Issue