3 # Copyright 2012 Software freedom conservancy
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
19 from selenium.webdriver.remote.command import Command
20 from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
21 from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
22 from selenium.common.exceptions import WebDriverException
23 from service import Service
25 class WebDriver(RemoteWebDriver):
27 Wrapper to communicate with PhantomJS through Ghostdriver.
29 You will need to follow all the directions here:
30 https://github.com/detro/ghostdriver
33 def __init__(self, executable_path="phantomjs",
34 port=0, desired_capabilities=DesiredCapabilities.PHANTOMJS):
36 Creates a new instance of the PhantomJS / Ghostdriver.
38 Starts the service and then creates new instance of the driver.
41 - executable_path - path to the executable. If the default is used it assumes the executable is in the $PATH
42 - port - port you would like the service to run, if left as 0, a free port will be found.
43 - desired_capabilities: Dictionary object with non-browser specific
44 capabilities only, such as "proxy" or "loggingPref".
46 self.service = Service(executable_path, port=port)
50 RemoteWebDriver.__init__(self,
51 command_executor=self.service.service_url,
52 desired_capabilities=desired_capabilities)
59 Closes the browser and shuts down the PhantomJS executable
60 that is started when starting the PhantomJS
63 RemoteWebDriver.quit(self)
65 # We don't care about the message because something probably has gone wrong