Skip to content

Commit 79f5c19

Browse files
committed
making keep-alive a flag to pass in to RemoteWebDriver defaults to false, FF & Chrome set it to true.
1 parent ce09d72 commit 79f5c19

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

Diff for: py/selenium/webdriver/chrome/webdriver.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ def __init__(self, executable_path="chromedriver", port=0,
6161
try:
6262
RemoteWebDriver.__init__(self,
6363
command_executor=self.service.service_url,
64-
desired_capabilities=desired_capabilities)
64+
desired_capabilities=desired_capabilities,
65+
keep_alive=True)
6566
except:
6667
self.quit()
6768
raise

Diff for: py/selenium/webdriver/firefox/extension_connection.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def __init__(self, host, firefox_profile, firefox_binary=None, timeout=30):
4747
self.binary.launch_browser(self.profile)
4848
_URL = "http://%s:%d/hub" % (HOST, PORT)
4949
RemoteConnection.__init__(
50-
self, _URL)
50+
self, _URL, keep_alive=True)
5151

5252
def quit(self, sessionId=None):
5353
self.execute(Command.QUIT, {'sessionId':sessionId})

Diff for: py/selenium/webdriver/firefox/webdriver.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ def __init__(self, firefox_profile=None, firefox_binary=None, timeout=30,
5757
RemoteWebDriver.__init__(self,
5858
command_executor=ExtensionConnection("127.0.0.1", self.profile,
5959
self.binary, timeout),
60-
desired_capabilities=capabilities)
60+
desired_capabilities=capabilities,
61+
keep_alive=True)
6162
self._is_remote = False
6263

6364
def quit(self):

Diff for: py/selenium/webdriver/remote/remote_connection.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ class RemoteConnection(object):
4848
Communicates with the server using the WebDriver wire protocol:
4949
http://code.google.com/p/selenium/wiki/JsonWireProtocol
5050
"""
51-
def __init__(self, remote_server_addr):
51+
def __init__(self, remote_server_addr, keep_alive=False):
5252
# Attempt to resolve the hostname and get an IP address.
53+
self.keep_alive = keep_alive
5354
parsed_url = parse.urlparse(remote_server_addr)
5455
addr = ""
5556
if parsed_url.hostname:
@@ -277,10 +278,12 @@ def _request(self, url, data=None, method=None):
277278
LOGGER.debug('%s %s %s' % (method, url, data))
278279

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

285288
# for basic auth
286289
if parsed_url.username:

Diff for: py/selenium/webdriver/remote/webdriver.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class WebDriver(object):
4545
"""
4646

4747
def __init__(self, command_executor='http://127.0.0.1:4444/wd/hub',
48-
desired_capabilities=None, browser_profile=None, proxy=None):
48+
desired_capabilities=None, browser_profile=None, proxy=None, keep_alive=False):
4949
"""
5050
Create a new driver that will issue commands using the wire protocol.
5151
@@ -62,7 +62,7 @@ def __init__(self, command_executor='http://127.0.0.1:4444/wd/hub',
6262
proxy.add_to_capabilities(desired_capabilities)
6363
self.command_executor = command_executor
6464
if type(self.command_executor) is bytes or type(self.command_executor) is str:
65-
self.command_executor = RemoteConnection(command_executor)
65+
self.command_executor = RemoteConnection(command_executor, keep_alive=keep_alive)
6666
self._is_remote = True
6767
self.session_id = None
6868
self.capabilities = {}

0 commit comments

Comments
 (0)