Skip to content

Commit de23cf5

Browse files
committed
create a temp file for cookies in phantomjs if not specified
Fixes #1783
1 parent 6427129 commit de23cf5

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

py/selenium/webdriver/phantomjs/service.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17+
import os
18+
import tempfile
1719
from selenium.webdriver.common import service
1820

1921

@@ -39,10 +41,18 @@ def __init__(self, executable_path, port=0, service_args=None, log_path=None):
3941
self.service_args=service_args[:]
4042
if not log_path:
4143
log_path = "ghostdriver.log"
44+
if not self._args_contain("--cookies-file="):
45+
self._cookie_temp_file = tempfile.mkstemp()[1]
46+
self.service_args.append("cookies-file=" + self._cookie_temp_file)
47+
else:
48+
self._cookie_temp_file = None
4249

4350
service.Service.__init__(self, executable_path, port=port, log_file=open(log_path, 'w'))
4451

4552

53+
def _args_contain(self, arg):
54+
return len(filter(lambda x:x.startswith(arg), self.service_args)) > 0
55+
4656
def command_line_args(self):
4757
return self.service_args + ["--webdriver=%d" % self.port]
4858

@@ -54,4 +64,5 @@ def service_url(self):
5464
return "http://localhost:%d/wd/hub" % self.port
5565

5666
def send_remote_shutdown_command(self):
57-
pass
67+
if self._cookie_temp_file:
68+
os.remove(self._cookie_temp_file)

0 commit comments

Comments
 (0)