Skip to content

Commit

Permalink
[py] add keep_alive to webdriver args
Browse files Browse the repository at this point in the history
  • Loading branch information
lmtierney authored and Grigory Mischenko committed Sep 20, 2018
1 parent 28e8dc3 commit e25e517
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 22 deletions.
13 changes: 9 additions & 4 deletions py/selenium/webdriver/chrome/webdriver.py
Expand Up @@ -33,7 +33,7 @@ class WebDriver(RemoteWebDriver):
def __init__(self, executable_path="chromedriver", port=0,
options=None, service_args=None,
desired_capabilities=None, service_log_path=None,
chrome_options=None):
chrome_options=None, keep_alive=True):
"""
Creates a new instance of the chrome driver.
Expand All @@ -42,9 +42,13 @@ def __init__(self, executable_path="chromedriver", port=0,
:Args:
- executable_path - path to the executable. If the default is used it assumes the executable is in the $PATH
- port - port you would like the service to run, if left as 0, a free port will be found.
- desired_capabilities: Dictionary object with non-browser specific
- options - this takes an instance of ChromeOptions
- service_args - List of args to pass to the driver service
- desired_capabilities - Dictionary object with non-browser specific
capabilities only, such as "proxy" or "loggingPref".
- options: this takes an instance of ChromeOptions
- service_log_path - Where to log information from the driver.
- chrome_options - Deprecated argument for options
- keep_alive - Whether to configure ChromeRemoteConnection to use HTTP keep-alive.
"""
if chrome_options:
warnings.warn('use options instead of chrome_options',
Expand Down Expand Up @@ -72,7 +76,8 @@ def __init__(self, executable_path="chromedriver", port=0,
RemoteWebDriver.__init__(
self,
command_executor=ChromeRemoteConnection(
remote_server_addr=self.service.service_url),
remote_server_addr=self.service.service_url,
keep_alive=keep_alive),
desired_capabilities=desired_capabilities)
except Exception:
self.quit()
Expand Down
21 changes: 19 additions & 2 deletions py/selenium/webdriver/edge/webdriver.py
Expand Up @@ -26,7 +26,23 @@
class WebDriver(RemoteWebDriver):

def __init__(self, executable_path='MicrosoftWebDriver.exe',
capabilities=None, port=0, verbose=False, service_log_path=None, log_path=None):
capabilities=None, port=0, verbose=False, service_log_path=None,
log_path=None, keep_alive=False):
"""
Creates a new instance of the chrome driver.
Starts the service and then creates new instance of chrome driver.
:Args:
- executable_path - path to the executable. If the default is used it assumes the executable is in the $PATH
- capabilities - Dictionary object with non-browser specific
capabilities only, such as "proxy" or "loggingPref".
- port - port you would like the service to run, if left as 0, a free port will be found.
- verbose - whether to set verbose logging in the service
- service_log_path - Where to log information from the driver.
- log_path: Deprecated argument for service_log_path
- keep_alive - Whether to configure ChromeRemoteConnection to use HTTP keep-alive.
"""
if log_path:
warnings.warn('use service_log_path instead of log_path',
DeprecationWarning, stacklevel=2)
Expand All @@ -45,7 +61,8 @@ def __init__(self, executable_path='MicrosoftWebDriver.exe',
RemoteWebDriver.__init__(
self,
command_executor=RemoteConnection('http://localhost:%d' % self.port,
resolve_ip=False),
resolve_ip=False,
keep_alive=keep_alive),
desired_capabilities=capabilities)
self._is_remote = False

Expand Down
11 changes: 8 additions & 3 deletions py/selenium/webdriver/firefox/webdriver.py
Expand Up @@ -51,7 +51,8 @@ def __init__(self, firefox_profile=None, firefox_binary=None,
timeout=30, capabilities=None, proxy=None,
executable_path="geckodriver", options=None,
service_log_path="geckodriver.log", firefox_options=None,
service_args=None, desired_capabilities=None, log_path=None):
service_args=None, desired_capabilities=None, log_path=None,
keep_alive=True):
"""Starts a new local session of Firefox.
Based on the combination and specificity of the various keyword
Expand Down Expand Up @@ -95,10 +96,14 @@ def __init__(self, firefox_profile=None, firefox_binary=None,
defaults to picking up the binary from the system path.
:param options: Instance of ``options.Options``.
:param service_log_path: Where to log information from the driver.
:param firefox_options: Deprecated argument for options
:param service_args: List of args to pass to the driver service
:param desired_capabilities: alias of capabilities. In future
versions of this library, this will replace 'capabilities'.
This will make the signature consistent with RemoteWebDriver.
:param log_path: Deprecated argument for service_log_path
:param keep_alive: Whether to configure remote_connection.RemoteConnection to use
HTTP keep-alive.
"""
if log_path:
warnings.warn('use service_log_path instead of log_path',
Expand Down Expand Up @@ -188,7 +193,7 @@ def __init__(self, firefox_profile=None, firefox_binary=None,
self,
command_executor=executor,
desired_capabilities=capabilities,
keep_alive=True)
keep_alive=keep_alive)

self._is_remote = False

Expand Down
14 changes: 10 additions & 4 deletions py/selenium/webdriver/ie/webdriver.py
Expand Up @@ -34,7 +34,7 @@ class WebDriver(RemoteWebDriver):
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=None,
ie_options=None, desired_capabilities=None, log_file=None):
ie_options=None, desired_capabilities=None, log_file=None, keep_alive=False):
"""
Creates a new instance of the chrome driver.
Expand All @@ -44,10 +44,15 @@ def __init__(self, executable_path='IEDriverServer.exe', capabilities=None,
- executable_path - path to the executable. If the default is used it assumes the executable is in the $PATH
- capabilities: capabilities Dictionary object
- port - port you would like the service to run, if left as 0, a free port will be found.
- timeout - no longer used, kept for backward compatibility
- host - IP address for the service
- log_level - log level you would like the service to run.
- service_log_path - target of logging of service, may be "stdout", "stderr" or file path.
- options: IE Options instance, providing additional IE options
- desired_capabilities: alias of capabilities; this will make the signature consistent with RemoteWebDriver.
- options - IE Options instance, providing additional IE options
- ie_options - Deprecated argument for options
- desired_capabilities - alias of capabilities; this will make the signature consistent with RemoteWebDriver.
- log_file - Deprecated argument for service_log_path
- keep_alive - Whether to configure RemoteConnection to use HTTP keep-alive.
"""
if log_file:
warnings.warn('use service_log_path instead of log_file',
Expand Down Expand Up @@ -88,7 +93,8 @@ def __init__(self, executable_path='IEDriverServer.exe', capabilities=None,
RemoteWebDriver.__init__(
self,
command_executor='http://localhost:%d' % self.port,
desired_capabilities=capabilities)
desired_capabilities=capabilities,
keep_alive=keep_alive)
self._is_remote = False

def quit(self):
Expand Down
10 changes: 7 additions & 3 deletions py/selenium/webdriver/opera/webdriver.py
Expand Up @@ -27,7 +27,7 @@ class OperaDriver(ChromiumDriver):
def __init__(self, executable_path=None, port=0,
options=None, service_args=None,
desired_capabilities=None, service_log_path=None,
opera_options=None):
opera_options=None, keep_alive=True):
"""
Creates a new instance of the operadriver.
Expand All @@ -38,9 +38,12 @@ def __init__(self, executable_path=None, port=0,
it assumes the executable is in the $PATH
- port - port you would like the service to run, if left as 0,
a free port will be found.
- options: this takes an instance of OperaOptions
- service_args - List of args to pass to the driver service
- desired_capabilities: Dictionary object with non-browser specific
- service_log_path - Where to log information from the driver.
- opera_options - Deprecated argument for options
capabilities only, such as "proxy" or "loggingPref".
- options: this takes an instance of ChromeOptions
"""
if opera_options:
warnings.warn('use options instead of opera_options',
Expand All @@ -55,7 +58,8 @@ def __init__(self, executable_path=None, port=0,
options=options,
service_args=service_args,
desired_capabilities=desired_capabilities,
service_log_path=service_log_path)
service_log_path=service_log_path,
keep_alive=keep_alive)

def create_options(self):
return Options()
Expand Down
12 changes: 8 additions & 4 deletions py/selenium/webdriver/safari/webdriver.py
Expand Up @@ -34,25 +34,29 @@ class WebDriver(RemoteWebDriver):
"""

def __init__(self, port=0, executable_path="/usr/bin/safaridriver", reuse_service=False,
desired_capabilities=DesiredCapabilities.SAFARI, quiet=False):
desired_capabilities=DesiredCapabilities.SAFARI, quiet=False,
keep_alive=True):
"""
Creates a new Safari driver instance and launches or finds a running safaridriver service.
:Args:
- port - The port on which the safaridriver service should listen for new connections. If zero, a free port will be found.
- quiet - If True, the driver's stdout and stderr is suppressed.
- executable_path - Path to a custom safaridriver executable to be used. If absent, /usr/bin/safaridriver is used.
- desired_capabilities: Dictionary object with desired capabilities (Can be used to provide various Safari switches).
- reuse_service - If True, do not spawn a safaridriver instance; instead, connect to an already-running service that was launched externally.
- desired_capabilities: Dictionary object with desired capabilities (Can be used to provide various Safari switches).
- quiet - If True, the driver's stdout and stderr is suppressed.
- keep_alive - Whether to configure SafariRemoteConnection to use
HTTP keep-alive. Defaults to False.
"""

self._reuse_service = reuse_service
self.service = Service(executable_path, port=port, quiet=quiet)
if not reuse_service:
self.service.start()

executor = SafariRemoteConnection(remote_server_addr=self.service.service_url)
executor = SafariRemoteConnection(remote_server_addr=self.service.service_url,
keep_alive=keep_alive)

RemoteWebDriver.__init__(
self,
Expand Down
6 changes: 4 additions & 2 deletions py/selenium/webdriver/webkitgtk/webdriver.py
Expand Up @@ -32,7 +32,7 @@ class WebDriver(RemoteWebDriver):

def __init__(self, executable_path="WebKitWebDriver", port=0, options=None,
desired_capabilities=DesiredCapabilities.WEBKITGTK,
service_log_path=None):
service_log_path=None, keep_alive=False):
"""
Creates a new instance of the WebKitGTK driver.
Expand All @@ -44,6 +44,7 @@ def __init__(self, executable_path="WebKitWebDriver", port=0, options=None,
- options : an instance of WebKitGTKOptions
- desired_capabilities : Dictionary object with desired capabilities
- service_log_path : Path to write service stdout and stderr output.
- keep_alive : Whether to configure RemoteConnection to use HTTP keep-alive.
"""
if options is not None:
capabilities = options.to_capabilities()
Expand All @@ -56,7 +57,8 @@ def __init__(self, executable_path="WebKitWebDriver", port=0, options=None,
RemoteWebDriver.__init__(
self,
command_executor=self.service.service_url,
desired_capabilities=desired_capabilities)
desired_capabilities=desired_capabilities,
keep_alive=keep_alive)
self._is_remote = False

def quit(self):
Expand Down

0 comments on commit e25e517

Please sign in to comment.