Skip to content

Commit

Permalink
create a temp file for cookies in phantomjs if not specified
Browse files Browse the repository at this point in the history
Fixes #1783
  • Loading branch information
lukeis committed Mar 11, 2016
1 parent 6427129 commit de23cf5
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion py/selenium/webdriver/phantomjs/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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]

Expand All @@ -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)

0 comments on commit de23cf5

Please sign in to comment.