Skip to content

Commit

Permalink
LukeIS: [python] ghostdriver can now be kicked off via command line o…
Browse files Browse the repository at this point in the history
…ption.

r18204
  • Loading branch information
lukeis committed Nov 26, 2012
1 parent 9cdb837 commit 508b83e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
11 changes: 4 additions & 7 deletions py/selenium/webdriver/phantomjs/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ class Service(object):
Object that manages the starting and stopping of PhantomJS / Ghostdriver
"""

def __init__(self, executable_path, ghostdriver_path, port=0, service_args=None):
def __init__(self, executable_path, port=0, service_args=None):
"""
Creates a new instance of the Service
:Args:
- executable_path : Path to PhantomJS binary
- ghostdriver_path : Path to ghostdriver/src/main.js
- port : Port the service is running on
- service_args : A List of other command line options to pass to PhantomJS
"""
Expand All @@ -43,8 +42,7 @@ def __init__(self, executable_path, ghostdriver_path, port=0, service_args=None)
if self.service_args is None:
self.service_args = []
self.service_args.insert(0, self.path)
self.service_args.append(ghostdriver_path)
self.service_args.append("%d" % self.port)
self.service_args.append("--webdriver=%d" % self.port)
self._log = open("ghostdriver.log", 'w')

def start(self):
Expand All @@ -56,11 +54,10 @@ def start(self):
or when it can't connect to the service
"""
try:
print "Starting process:", self.path
self.process = subprocess.Popen(self.service_args,
stdout=self._log, stderr=self._log)
except:
raise WebDriverException("Unable to start phantomjs with ghostdriver.")
except Exception, e:
raise WebDriverException("Unable to start phantomjs with ghostdriver.", e)
count = 0
while not utils.is_connectable(self.port):
count += 1
Expand Down
5 changes: 2 additions & 3 deletions py/selenium/webdriver/phantomjs/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,20 @@ class WebDriver(RemoteWebDriver):
https://github.com/detro/ghostdriver
"""

def __init__(self, ghostdriver_path, executable_path="phantomjs",
def __init__(self, executable_path="phantomjs",
port=0, desired_capabilities=DesiredCapabilities.PHANTOMJS):
"""
Creates a new instance of the PhantomJS / Ghostdriver.
Starts the service and then creates new instance of the driver.
:Args:
- ghostdriver_path - path to ghostdriver/src/main.js
- executable_path - path to the executable. If the default is used it assumes the executable is in the $PATH
- port - port you would like the service to run, if left as 0, a free port will be found.
- desired_capabilities: Dictionary object with non-browser specific
capabilities only, such as "proxy" or "loggingPref".
"""
self.service = Service(executable_path, ghostdriver_path, port=port)
self.service = Service(executable_path, port=port)
self.service.start()

try:
Expand Down
1 change: 0 additions & 1 deletion rake-tasks/browsers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
:dir => "phantomjs",
:file_string => "phantomjs",
:class => "PhantomJS",
:constructor_args => "'../ghostdriver/src/main.js'"
},
:browser_name => "phantomjs",
},
Expand Down

0 comments on commit 508b83e

Please sign in to comment.