Skip to content

Commit b678e44

Browse files
committed
Turn proxy string warnings into errors (configurable)
1 parent 8ccc2c4 commit b678e44

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

seleniumbase/config/settings.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@
6969
# Messenger notifications appear when reaching assert statements in Demo Mode.
7070
DEFAULT_MESSAGE_DURATION = 2.55
7171

72+
# If True, an Exception is raised immediately for invalid proxy string syntax.
73+
# If False, a Warning will appear after the test, with no proxy server used.
74+
# (This applies when using --proxy=[PROXY_STRING] for using a proxy server.)
75+
RAISE_INVALID_PROXY_STRING_EXCEPTION = True
76+
7277
# #####>>>>>----- MasterQA SETTINGS -----<<<<<#####
7378
# ##### (Used when importing MasterQA as the parent class)
7479

seleniumbase/core/browser_launcher.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from selenium.common.exceptions import WebDriverException
1010
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
1111
from seleniumbase.config import proxy_list
12+
from seleniumbase.config import settings
1213
from seleniumbase.core import download_helper
1314
from seleniumbase.core import proxy_helper
1415
from seleniumbase.core import capabilities_parser
@@ -150,12 +151,16 @@ def _create_firefox_profile(downloads_path, proxy_string):
150151
def display_proxy_warning(proxy_string):
151152
message = ('\n\nWARNING: Proxy String ["%s"] is NOT in the expected '
152153
'"ip_address:port" or "server:port" format, '
153-
'(OR the key does not exist in proxy_list.PROXY_LIST). '
154-
'*** DEFAULTING to NOT USING a Proxy Server! ***'
154+
'(OR the key does not exist in '
155+
'seleniumbase.config.proxy_list.PROXY_LIST).'
155156
% proxy_string)
156-
warnings.simplefilter('always', Warning) # See Warnings
157-
warnings.warn(message, category=Warning, stacklevel=2)
158-
warnings.simplefilter('default', Warning) # Set Default
157+
if settings.RAISE_INVALID_PROXY_STRING_EXCEPTION:
158+
raise Exception(message)
159+
else:
160+
message += ' *** DEFAULTING to NOT USING a Proxy Server! ***'
161+
warnings.simplefilter('always', Warning) # See Warnings
162+
warnings.warn(message, category=Warning, stacklevel=2)
163+
warnings.simplefilter('default', Warning) # Set Default
159164

160165

161166
def validate_proxy_string(proxy_string):

0 commit comments

Comments
 (0)