Skip to content

Commit c89807a

Browse files
authored
[py] deprecate all but Options and Service arguments in driver instantiation. (#9128)
* [py] Deprecate __init__ params Deprecated left out keep_alive for IE & Chrome Driver and Added Deprecation warning for missing desired_capabilites for IE driver currently left is - browser_name, vendor_prefix for chromium driver family Fixes #9125
1 parent ea933bd commit c89807a

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

py/selenium/webdriver/chrome/webdriver.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
DEFAULT_PORT = 0
2525
DEFAULT_SERVICE_LOG_PATH = None
26+
DEFAULT_KEEP_ALIVE = None
2627

2728

2829
class WebDriver(ChromiumDriver):
@@ -35,7 +36,7 @@ class WebDriver(ChromiumDriver):
3536
def __init__(self, executable_path="chromedriver", port=DEFAULT_PORT,
3637
options: Options = None, service_args=None,
3738
desired_capabilities=None, service_log_path=DEFAULT_SERVICE_LOG_PATH,
38-
chrome_options=None, service: Service = None, keep_alive=True):
39+
chrome_options=None, service: Service = None, keep_alive=DEFAULT_KEEP_ALIVE):
3940
"""
4041
Creates a new instance of the chrome driver.
4142
Starts the service and then creates new instance of chrome driver.
@@ -48,7 +49,7 @@ def __init__(self, executable_path="chromedriver", port=DEFAULT_PORT,
4849
- desired_capabilities - Deprecated: Dictionary object with non-browser specific
4950
capabilities only, such as "proxy" or "loggingPref".
5051
- service_log_path - Deprecated: Where to log information from the driver.
51-
- keep_alive - Whether to configure ChromeRemoteConnection to use HTTP keep-alive.
52+
- keep_alive - Deprecated: Whether to configure ChromeRemoteConnection to use HTTP keep-alive.
5253
"""
5354
if executable_path != 'chromedriver':
5455
warnings.warn('executable_path has been deprecated, please pass in a Service object',
@@ -57,7 +58,11 @@ def __init__(self, executable_path="chromedriver", port=DEFAULT_PORT,
5758
warnings.warn('use options instead of chrome_options',
5859
DeprecationWarning, stacklevel=2)
5960
options = chrome_options
60-
61+
if keep_alive != DEFAULT_KEEP_ALIVE:
62+
warnings.warn('keep_alive has been deprecated, please pass in a Service object',
63+
DeprecationWarning, stacklevel=2)
64+
else:
65+
keep_alive = True
6166
if not service:
6267
service = Service(executable_path, port, service_args, service_log_path)
6368

py/selenium/webdriver/chromium/webdriver.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
DEFAULT_PORT = 0
2727
DEFAULT_SERVICE_LOG_PATH = None
28+
DEFAULT_KEEP_ALIVE = None
2829

2930

3031
class ChromiumDriver(RemoteWebDriver):
@@ -35,7 +36,7 @@ class ChromiumDriver(RemoteWebDriver):
3536
def __init__(self, browser_name, vendor_prefix,
3637
port=DEFAULT_PORT, options: Options = None, service_args=None,
3738
desired_capabilities=None, service_log_path=DEFAULT_SERVICE_LOG_PATH,
38-
service: Service = None, keep_alive=True):
39+
service: Service = None, keep_alive=DEFAULT_KEEP_ALIVE):
3940
"""
4041
Creates a new WebDriver instance of the ChromiumDriver.
4142
Starts the service and then creates new WebDriver instance of ChromiumDriver.
@@ -49,7 +50,7 @@ def __init__(self, browser_name, vendor_prefix,
4950
- desired_capabilities - Deprecated: Dictionary object with non-browser specific
5051
capabilities only, such as "proxy" or "loggingPref".
5152
- service_log_path - Deprecated: Where to log information from the driver.
52-
- keep_alive - Whether to configure ChromiumRemoteConnection to use HTTP keep-alive.
53+
- keep_alive - Deprecated: Whether to configure ChromiumRemoteConnection to use HTTP keep-alive.
5354
"""
5455
if desired_capabilities:
5556
warnings.warn('desired_capabilities has been deprecated, please pass in a Service object',
@@ -61,6 +62,11 @@ def __init__(self, browser_name, vendor_prefix,
6162
if service_log_path != DEFAULT_SERVICE_LOG_PATH:
6263
warnings.warn('service_log_path has been deprecated, please pass in a Service object',
6364
DeprecationWarning, stacklevel=2)
65+
if keep_alive != DEFAULT_KEEP_ALIVE and type(self) == __class__:
66+
warnings.warn('keep_alive has been deprecated, please pass in a Service object',
67+
DeprecationWarning, stacklevel=2)
68+
else:
69+
keep_alive = True
6470

6571
_ignore_proxy = None
6672
if not options:

py/selenium/webdriver/ie/webdriver.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
DEFAULT_HOST = None
2929
DEFAULT_LOG_LEVEL = None
3030
DEFAULT_SERVICE_LOG_PATH = None
31+
DEFAULT_KEEP_ALIVE = None
3132

3233

3334
class WebDriver(RemoteWebDriver):
@@ -37,7 +38,7 @@ def __init__(self, executable_path='IEDriverServer.exe', capabilities=None,
3738
port=DEFAULT_PORT, timeout=DEFAULT_TIMEOUT, host=DEFAULT_HOST,
3839
log_level=DEFAULT_LOG_LEVEL, service_log_path=DEFAULT_SERVICE_LOG_PATH,
3940
options: Options = None, service: Service = None,
40-
desired_capabilities=None, keep_alive=False):
41+
desired_capabilities=None, keep_alive=DEFAULT_KEEP_ALIVE):
4142
"""
4243
Creates a new instance of the Ie driver.
4344
@@ -53,7 +54,7 @@ def __init__(self, executable_path='IEDriverServer.exe', capabilities=None,
5354
- service_log_path - Deprecated: target of logging of service, may be "stdout", "stderr" or file path.
5455
- options - IE Options instance, providing additional IE options
5556
- desired_capabilities - Deprecated: alias of capabilities; this will make the signature consistent with RemoteWebDriver.
56-
- keep_alive - Whether to configure RemoteConnection to use HTTP keep-alive.
57+
- keep_alive - Deprecated: Whether to configure RemoteConnection to use HTTP keep-alive.
5758
"""
5859
if executable_path != 'IEDriverServer.exe':
5960
warnings.warn('executable_path has been deprecated, please pass in a Service object',
@@ -70,13 +71,22 @@ def __init__(self, executable_path='IEDriverServer.exe', capabilities=None,
7071
if host != DEFAULT_HOST:
7172
warnings.warn('host has been deprecated, please pass in a Service object',
7273
DeprecationWarning, stacklevel=2)
73-
self.host = host
7474
if log_level != DEFAULT_LOG_LEVEL:
7575
warnings.warn('log_level has been deprecated, please pass in a Service object',
7676
DeprecationWarning, stacklevel=2)
7777
if service_log_path != DEFAULT_SERVICE_LOG_PATH:
7878
warnings.warn('service_log_path has been deprecated, please pass in a Service object',
7979
DeprecationWarning, stacklevel=2)
80+
if desired_capabilities:
81+
warnings.warn('desired_capabilities has been deprecated, please pass in a Service object',
82+
DeprecationWarning, stacklevel=2)
83+
if keep_alive != DEFAULT_KEEP_ALIVE:
84+
warnings.warn('keep_alive has been deprecated, please pass in a Service object',
85+
DeprecationWarning, stacklevel=2)
86+
else:
87+
keep_alive = False
88+
89+
self.host = host
8090
self.port = port
8191
if self.port == 0:
8292
self.port = utils.free_port()

0 commit comments

Comments
 (0)