Skip to content

Commit

Permalink
[py] deprecate all but Options and Service arguments in driver in…
Browse files Browse the repository at this point in the history
…stantiation. (#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
  • Loading branch information
itsjwala authored Feb 4, 2021
1 parent ea933bd commit c89807a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
11 changes: 8 additions & 3 deletions py/selenium/webdriver/chrome/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

DEFAULT_PORT = 0
DEFAULT_SERVICE_LOG_PATH = None
DEFAULT_KEEP_ALIVE = None


class WebDriver(ChromiumDriver):
Expand All @@ -35,7 +36,7 @@ class WebDriver(ChromiumDriver):
def __init__(self, executable_path="chromedriver", port=DEFAULT_PORT,
options: Options = None, service_args=None,
desired_capabilities=None, service_log_path=DEFAULT_SERVICE_LOG_PATH,
chrome_options=None, service: Service = None, keep_alive=True):
chrome_options=None, service: Service = None, keep_alive=DEFAULT_KEEP_ALIVE):
"""
Creates a new instance of the chrome driver.
Starts the service and then creates new instance of chrome driver.
Expand All @@ -48,7 +49,7 @@ def __init__(self, executable_path="chromedriver", port=DEFAULT_PORT,
- desired_capabilities - Deprecated: Dictionary object with non-browser specific
capabilities only, such as "proxy" or "loggingPref".
- service_log_path - Deprecated: Where to log information from the driver.
- keep_alive - Whether to configure ChromeRemoteConnection to use HTTP keep-alive.
- keep_alive - Deprecated: Whether to configure ChromeRemoteConnection to use HTTP keep-alive.
"""
if executable_path != 'chromedriver':
warnings.warn('executable_path has been deprecated, please pass in a Service object',
Expand All @@ -57,7 +58,11 @@ def __init__(self, executable_path="chromedriver", port=DEFAULT_PORT,
warnings.warn('use options instead of chrome_options',
DeprecationWarning, stacklevel=2)
options = chrome_options

if keep_alive != DEFAULT_KEEP_ALIVE:
warnings.warn('keep_alive has been deprecated, please pass in a Service object',
DeprecationWarning, stacklevel=2)
else:
keep_alive = True
if not service:
service = Service(executable_path, port, service_args, service_log_path)

Expand Down
10 changes: 8 additions & 2 deletions py/selenium/webdriver/chromium/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

DEFAULT_PORT = 0
DEFAULT_SERVICE_LOG_PATH = None
DEFAULT_KEEP_ALIVE = None


class ChromiumDriver(RemoteWebDriver):
Expand All @@ -35,7 +36,7 @@ class ChromiumDriver(RemoteWebDriver):
def __init__(self, browser_name, vendor_prefix,
port=DEFAULT_PORT, options: Options = None, service_args=None,
desired_capabilities=None, service_log_path=DEFAULT_SERVICE_LOG_PATH,
service: Service = None, keep_alive=True):
service: Service = None, keep_alive=DEFAULT_KEEP_ALIVE):
"""
Creates a new WebDriver instance of the ChromiumDriver.
Starts the service and then creates new WebDriver instance of ChromiumDriver.
Expand All @@ -49,7 +50,7 @@ def __init__(self, browser_name, vendor_prefix,
- desired_capabilities - Deprecated: Dictionary object with non-browser specific
capabilities only, such as "proxy" or "loggingPref".
- service_log_path - Deprecated: Where to log information from the driver.
- keep_alive - Whether to configure ChromiumRemoteConnection to use HTTP keep-alive.
- keep_alive - Deprecated: Whether to configure ChromiumRemoteConnection to use HTTP keep-alive.
"""
if desired_capabilities:
warnings.warn('desired_capabilities has been deprecated, please pass in a Service object',
Expand All @@ -61,6 +62,11 @@ def __init__(self, browser_name, vendor_prefix,
if service_log_path != DEFAULT_SERVICE_LOG_PATH:
warnings.warn('service_log_path has been deprecated, please pass in a Service object',
DeprecationWarning, stacklevel=2)
if keep_alive != DEFAULT_KEEP_ALIVE and type(self) == __class__:
warnings.warn('keep_alive has been deprecated, please pass in a Service object',
DeprecationWarning, stacklevel=2)
else:
keep_alive = True

_ignore_proxy = None
if not options:
Expand Down
16 changes: 13 additions & 3 deletions py/selenium/webdriver/ie/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
DEFAULT_HOST = None
DEFAULT_LOG_LEVEL = None
DEFAULT_SERVICE_LOG_PATH = None
DEFAULT_KEEP_ALIVE = None


class WebDriver(RemoteWebDriver):
Expand All @@ -37,7 +38,7 @@ def __init__(self, executable_path='IEDriverServer.exe', capabilities=None,
port=DEFAULT_PORT, timeout=DEFAULT_TIMEOUT, host=DEFAULT_HOST,
log_level=DEFAULT_LOG_LEVEL, service_log_path=DEFAULT_SERVICE_LOG_PATH,
options: Options = None, service: Service = None,
desired_capabilities=None, keep_alive=False):
desired_capabilities=None, keep_alive=DEFAULT_KEEP_ALIVE):
"""
Creates a new instance of the Ie driver.
Expand All @@ -53,7 +54,7 @@ def __init__(self, executable_path='IEDriverServer.exe', capabilities=None,
- service_log_path - Deprecated: target of logging of service, may be "stdout", "stderr" or file path.
- options - IE Options instance, providing additional IE options
- desired_capabilities - Deprecated: alias of capabilities; this will make the signature consistent with RemoteWebDriver.
- keep_alive - Whether to configure RemoteConnection to use HTTP keep-alive.
- keep_alive - Deprecated: Whether to configure RemoteConnection to use HTTP keep-alive.
"""
if executable_path != 'IEDriverServer.exe':
warnings.warn('executable_path has been deprecated, please pass in a Service object',
Expand All @@ -70,13 +71,22 @@ def __init__(self, executable_path='IEDriverServer.exe', capabilities=None,
if host != DEFAULT_HOST:
warnings.warn('host has been deprecated, please pass in a Service object',
DeprecationWarning, stacklevel=2)
self.host = host
if log_level != DEFAULT_LOG_LEVEL:
warnings.warn('log_level has been deprecated, please pass in a Service object',
DeprecationWarning, stacklevel=2)
if service_log_path != DEFAULT_SERVICE_LOG_PATH:
warnings.warn('service_log_path has been deprecated, please pass in a Service object',
DeprecationWarning, stacklevel=2)
if desired_capabilities:
warnings.warn('desired_capabilities has been deprecated, please pass in a Service object',
DeprecationWarning, stacklevel=2)
if keep_alive != DEFAULT_KEEP_ALIVE:
warnings.warn('keep_alive has been deprecated, please pass in a Service object',
DeprecationWarning, stacklevel=2)
else:
keep_alive = False

self.host = host
self.port = port
if self.port == 0:
self.port = utils.free_port()
Expand Down

0 comments on commit c89807a

Please sign in to comment.