Skip to content

Commit

Permalink
making keep-alive a flag to pass in to RemoteWebDriver defaults to fa…
Browse files Browse the repository at this point in the history
…lse, FF & Chrome set it to true.
  • Loading branch information
lukeis committed Dec 12, 2013
1 parent ce09d72 commit 79f5c19
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
3 changes: 2 additions & 1 deletion py/selenium/webdriver/chrome/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def __init__(self, executable_path="chromedriver", port=0,
try:
RemoteWebDriver.__init__(self,
command_executor=self.service.service_url,
desired_capabilities=desired_capabilities)
desired_capabilities=desired_capabilities,
keep_alive=True)
except:
self.quit()
raise
Expand Down
2 changes: 1 addition & 1 deletion py/selenium/webdriver/firefox/extension_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(self, host, firefox_profile, firefox_binary=None, timeout=30):
self.binary.launch_browser(self.profile)
_URL = "http://%s:%d/hub" % (HOST, PORT)
RemoteConnection.__init__(
self, _URL)
self, _URL, keep_alive=True)

def quit(self, sessionId=None):
self.execute(Command.QUIT, {'sessionId':sessionId})
Expand Down
3 changes: 2 additions & 1 deletion py/selenium/webdriver/firefox/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def __init__(self, firefox_profile=None, firefox_binary=None, timeout=30,
RemoteWebDriver.__init__(self,
command_executor=ExtensionConnection("127.0.0.1", self.profile,
self.binary, timeout),
desired_capabilities=capabilities)
desired_capabilities=capabilities,
keep_alive=True)
self._is_remote = False

def quit(self):
Expand Down
7 changes: 5 additions & 2 deletions py/selenium/webdriver/remote/remote_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ class RemoteConnection(object):
Communicates with the server using the WebDriver wire protocol:
http://code.google.com/p/selenium/wiki/JsonWireProtocol
"""
def __init__(self, remote_server_addr):
def __init__(self, remote_server_addr, keep_alive=False):
# Attempt to resolve the hostname and get an IP address.
self.keep_alive = keep_alive
parsed_url = parse.urlparse(remote_server_addr)
addr = ""
if parsed_url.hostname:
Expand Down Expand Up @@ -277,10 +278,12 @@ def _request(self, url, data=None, method=None):
LOGGER.debug('%s %s %s' % (method, url, data))

parsed_url = parse.urlparse(url)
headers = {"Connection": "keep-alive", method: parsed_url.path,
headers = {method: parsed_url.path,
"User-Agent": "Python http auth",
"Content-type": "application/json;charset=\"UTF-8\"",
"Accept": "application/json"}
if self.keep_alive:
headers['Connection'] = 'keep-alive'

# for basic auth
if parsed_url.username:
Expand Down
4 changes: 2 additions & 2 deletions py/selenium/webdriver/remote/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class WebDriver(object):
"""

def __init__(self, command_executor='http://127.0.0.1:4444/wd/hub',
desired_capabilities=None, browser_profile=None, proxy=None):
desired_capabilities=None, browser_profile=None, proxy=None, keep_alive=False):
"""
Create a new driver that will issue commands using the wire protocol.
Expand All @@ -62,7 +62,7 @@ def __init__(self, command_executor='http://127.0.0.1:4444/wd/hub',
proxy.add_to_capabilities(desired_capabilities)
self.command_executor = command_executor
if type(self.command_executor) is bytes or type(self.command_executor) is str:
self.command_executor = RemoteConnection(command_executor)
self.command_executor = RemoteConnection(command_executor, keep_alive=keep_alive)
self._is_remote = True
self.session_id = None
self.capabilities = {}
Expand Down

0 comments on commit 79f5c19

Please sign in to comment.