org.openqa.selenium.phantomjs
Class PhantomJSDriver

java.lang.Object
  extended by org.openqa.selenium.remote.RemoteWebDriver
      extended by org.openqa.selenium.phantomjs.PhantomJSDriver
All Implemented Interfaces:
org.openqa.selenium.HasCapabilities, org.openqa.selenium.HasInputDevices, org.openqa.selenium.internal.FindsByClassName, org.openqa.selenium.internal.FindsByCssSelector, org.openqa.selenium.internal.FindsById, org.openqa.selenium.internal.FindsByLinkText, org.openqa.selenium.internal.FindsByName, org.openqa.selenium.internal.FindsByTagName, org.openqa.selenium.internal.FindsByXPath, org.openqa.selenium.JavascriptExecutor, org.openqa.selenium.SearchContext, org.openqa.selenium.TakesScreenshot, org.openqa.selenium.WebDriver

public class PhantomJSDriver
extends org.openqa.selenium.remote.RemoteWebDriver
implements org.openqa.selenium.TakesScreenshot

A WebDriver implementation that controls a PhantomJS running in Remote WebDriver mode. This class is provided as a convenience for easily testing PhantomJS. The control server which each instance communicates with will live and die with the instance.

The Driver requires to optionally set some Capabilities or Environment Variables:

PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY is required only if the executable phantomjs is not available through the $PATH environment variable: you can provide it either via the Capabilities construction parameter object, or via System Property.

PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_PATH_PROPERTY is optional in case you want to use a specific version of GhostDriver (i.e. during development of GhostDriver). You can provide it either via the Capabilities construction parameter object, or via System Property.

Instead, if you have a PhantomJS WebDriver process already running, you can instead use RemoteWebDriver.RemoteWebDriver(java.net.URL, org.openqa.selenium.Capabilities) to delegate the execution of your WebDriver/Selenium scripts to it. Of course, in that case you will than be in charge to control the life-cycle of the PhantomJS process.

NOTE: PhantomJS Remote WebDriver mode is implemented via GhostDriver. It's a separate project that, at every stable release, is merged into PhantomJS. If interested in developing (contributing to) GhostDriver, it's possible to run PhantomJS and pass GhostDriver as a script.

NOTE: The design of this class is heavily inspired by org.openqa.selenium.chrome.ChromeDriver.

See Also:
PhantomJSDriverService.createDefaultService()

Nested Class Summary
 
Nested classes/interfaces inherited from class org.openqa.selenium.remote.RemoteWebDriver
org.openqa.selenium.remote.RemoteWebDriver.RemoteTargetLocator, org.openqa.selenium.remote.RemoteWebDriver.RemoteWebDriverOptions, org.openqa.selenium.remote.RemoteWebDriver.When
 
Nested classes/interfaces inherited from interface org.openqa.selenium.WebDriver
org.openqa.selenium.WebDriver.ImeHandler, org.openqa.selenium.WebDriver.Navigation, org.openqa.selenium.WebDriver.Options, org.openqa.selenium.WebDriver.TargetLocator, org.openqa.selenium.WebDriver.Timeouts, org.openqa.selenium.WebDriver.Window
 
Constructor Summary
PhantomJSDriver(org.openqa.selenium.Capabilities desiredCapabilities)
          Creates a new PhantomJSDriver instance.
PhantomJSDriver(org.openqa.selenium.remote.service.DriverService service, org.openqa.selenium.Capabilities desiredCapabilities)
          Creates a new PhantomJSDriver instance.
 
Method Summary
<X> X
getScreenshotAs(org.openqa.selenium.OutputType<X> target)
          Take screenshot of the current window.
 
Methods inherited from class org.openqa.selenium.remote.RemoteWebDriver
close, execute, execute, executeAsyncScript, executeScript, findElement, findElement, findElementByClassName, findElementByCssSelector, findElementById, findElementByLinkText, findElementByName, findElementByPartialLinkText, findElementByTagName, findElementByXPath, findElements, findElements, findElementsByClassName, findElementsByCssSelector, findElementsById, findElementsByLinkText, findElementsByName, findElementsByPartialLinkText, findElementsByTagName, findElementsByXPath, get, getCapabilities, getCommandExecutor, getCurrentUrl, getElementConverter, getErrorHandler, getExecuteMethod, getFileDetector, getKeyboard, getMouse, getPageSource, getRemoteStatus, getSessionId, getTitle, getWindowHandle, getWindowHandles, log, manage, navigate, quit, setCommandExecutor, setElementConverter, setFileDetector, setFoundBy, setLogLevel, setSessionId, startClient, startSession, startSession, stopClient, switchTo, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PhantomJSDriver

public PhantomJSDriver(org.openqa.selenium.Capabilities desiredCapabilities)
Creates a new PhantomJSDriver instance.

Parameters:
desiredCapabilities - The capabilities required from PhantomJS/GhostDriver.
See Also:
for configuration details.

PhantomJSDriver

public PhantomJSDriver(org.openqa.selenium.remote.service.DriverService service,
                       org.openqa.selenium.Capabilities desiredCapabilities)
Creates a new PhantomJSDriver instance. The service will be started along with the driver, and shutdown upon calling RemoteWebDriver.quit().

Parameters:
service - The service to use.
desiredCapabilities - The capabilities required from PhantomJS/GhostDriver.
Method Detail

getScreenshotAs

public <X> X getScreenshotAs(org.openqa.selenium.OutputType<X> target)
                  throws org.openqa.selenium.WebDriverException
Take screenshot of the current window.

Specified by:
getScreenshotAs in interface org.openqa.selenium.TakesScreenshot
Parameters:
target - The target type/format of the Screenshot
Returns:
Screenshot of current window, in the requested format
Throws:
org.openqa.selenium.WebDriverException
See Also:
TakesScreenshot.getScreenshotAs(org.openqa.selenium.OutputType)