From de23cf5344fbd3b3a3b13111edb22bb1e519d806 Mon Sep 17 00:00:00 2001 From: Luke Inman-Semerau Date: Fri, 11 Mar 2016 08:19:14 -0800 Subject: [PATCH] create a temp file for cookies in phantomjs if not specified Fixes #1783 --- py/selenium/webdriver/phantomjs/service.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/py/selenium/webdriver/phantomjs/service.py b/py/selenium/webdriver/phantomjs/service.py index f32c17b50fbbb..289d5c995a4d8 100755 --- a/py/selenium/webdriver/phantomjs/service.py +++ b/py/selenium/webdriver/phantomjs/service.py @@ -14,6 +14,8 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. +import os +import tempfile from selenium.webdriver.common import service @@ -39,10 +41,18 @@ def __init__(self, executable_path, port=0, service_args=None, log_path=None): self.service_args=service_args[:] if not log_path: log_path = "ghostdriver.log" + if not self._args_contain("--cookies-file="): + self._cookie_temp_file = tempfile.mkstemp()[1] + self.service_args.append("cookies-file=" + self._cookie_temp_file) + else: + self._cookie_temp_file = None service.Service.__init__(self, executable_path, port=port, log_file=open(log_path, 'w')) + def _args_contain(self, arg): + return len(filter(lambda x:x.startswith(arg), self.service_args)) > 0 + def command_line_args(self): return self.service_args + ["--webdriver=%d" % self.port] @@ -54,4 +64,5 @@ def service_url(self): return "http://localhost:%d/wd/hub" % self.port def send_remote_shutdown_command(self): - pass + if self._cookie_temp_file: + os.remove(self._cookie_temp_file)