org.openqa.selenium.phantomjs
Class PhantomJSDriverService

java.lang.Object
  extended by org.openqa.selenium.remote.service.DriverService
      extended by org.openqa.selenium.phantomjs.PhantomJSDriverService

public class PhantomJSDriverService
extends org.openqa.selenium.remote.service.DriverService

Service that controls the life-cycle of a PhantomJS in Remote WebDriver mode. The Remote WebDriver is implemented via GhostDriver.

NOTE: Yes, the design of this class is heavily inspired by org.openqa.selenium.chrome.ChromeDriverService.


Nested Class Summary
static class PhantomJSDriverService.Builder
          Builder used to configure new PhantomJSDriverService instances.
 
Field Summary
static java.lang.String PHANTOMJS_CLI_ARGS
          Capability that allows to add custom command line arguments to the spawned PhantomJS process.
static java.lang.String PHANTOMJS_EXECUTABLE_PATH_PROPERTY
          System property/capability that defines the location of the PhantomJS executable.
static java.lang.String PHANTOMJS_GHOSTDRIVER_CLI_ARGS
          Capability that allows to pass custom command line arguments to the GhostDriver JavaScript launch file, spawned PhantomJS process.
static java.lang.String PHANTOMJS_GHOSTDRIVER_PATH_PROPERTY
          Optional System property/capability that defines the location of the GhostDriver JavaScript launch file (i.e.
static java.lang.String PHANTOMJS_PAGE_CUSTOMHEADERS_PREFIX
          Set capabilities with this prefix to apply it to the PhantomJS page.customHeaders.* object.
static java.lang.String PHANTOMJS_PAGE_SETTINGS_PREFIX
          Set capabilities with this prefix to apply it to the PhantomJS page.settings.* object.
 
Method Summary
static PhantomJSDriverService createDefaultService()
          Same as createDefaultService(org.openqa.selenium.Capabilities).
static PhantomJSDriverService createDefaultService(org.openqa.selenium.Capabilities desiredCapabilities)
          Configures and returns a new PhantomJSDriverService using the default configuration.
protected static java.io.File findGhostDriver(org.openqa.selenium.Capabilities desiredCapabilities, java.lang.String docsLink, java.lang.String downloadLink)
          Find the GhostDriver main file (i.e.
protected static java.io.File findPhantomJS(org.openqa.selenium.Capabilities desiredCapabilities, java.lang.String docsLink, java.lang.String downloadLink)
          Looks into the Capabilities, the current $PATH and the System Properties for PHANTOMJS_EXECUTABLE_PATH_PROPERTY.
 
Methods inherited from class org.openqa.selenium.remote.service.DriverService
checkExecutable, findExecutable, getUrl, isRunning, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PHANTOMJS_EXECUTABLE_PATH_PROPERTY

public static final java.lang.String PHANTOMJS_EXECUTABLE_PATH_PROPERTY
System property/capability that defines the location of the PhantomJS executable.

See Also:
Constant Field Values

PHANTOMJS_GHOSTDRIVER_PATH_PROPERTY

public static final java.lang.String PHANTOMJS_GHOSTDRIVER_PATH_PROPERTY
Optional System property/capability that defines the location of the GhostDriver JavaScript launch file (i.e. "src/main.js").

See Also:
Constant Field Values

PHANTOMJS_CLI_ARGS

public static final java.lang.String PHANTOMJS_CLI_ARGS
Capability that allows to add custom command line arguments to the spawned PhantomJS process.

Set this capability with a list of of argument strings to add, e.g. new String[] { "--ignore-ssl-errors=yes", "--load-images=no" }.

See Also:
Constant Field Values

PHANTOMJS_GHOSTDRIVER_CLI_ARGS

public static final java.lang.String PHANTOMJS_GHOSTDRIVER_CLI_ARGS
Capability that allows to pass custom command line arguments to the GhostDriver JavaScript launch file, spawned PhantomJS process. NOTE: This is useful only when used together with PhantomJSDriverService#PHANTOMJS_GHOSTDRIVER_PATH_PROPERTY.

Set this capability with a list of of argument strings to add, e.g. new String[] { "--logFile=PATH", "--logLevel=DEBUG" }.

Acceptable arguments:

See Also:
Constant Field Values

PHANTOMJS_PAGE_SETTINGS_PREFIX

public static final java.lang.String PHANTOMJS_PAGE_SETTINGS_PREFIX
Set capabilities with this prefix to apply it to the PhantomJS page.settings.* object. Every PhantomJS WebPage Setting can be used. See PhantomJS docs/a>.

See Also:
Constant Field Values

PHANTOMJS_PAGE_CUSTOMHEADERS_PREFIX

public static final java.lang.String PHANTOMJS_PAGE_CUSTOMHEADERS_PREFIX
Set capabilities with this prefix to apply it to the PhantomJS page.customHeaders.* object. Any header can be used. See PhantomJS docs/a>.

See Also:
Constant Field Values
Method Detail

createDefaultService

public static PhantomJSDriverService createDefaultService(org.openqa.selenium.Capabilities desiredCapabilities)
Configures and returns a new PhantomJSDriverService using the default configuration.

In this configuration, the service will use the PhantomJS executable identified by the the following capability, system property or PATH environment variables:

Each service created by this method will be configured to find and use a free port on the current system.

Returns:
A new ChromeDriverService using the default configuration.

createDefaultService

public static PhantomJSDriverService createDefaultService()
Same as createDefaultService(org.openqa.selenium.Capabilities).

In this case PhantomJS or GhostDriver can't be searched within the Capabilities, only System Properties.

Returns:
A new ChromeDriverService using the default configuration.

findPhantomJS

protected static java.io.File findPhantomJS(org.openqa.selenium.Capabilities desiredCapabilities,
                                            java.lang.String docsLink,
                                            java.lang.String downloadLink)
Looks into the Capabilities, the current $PATH and the System Properties for PHANTOMJS_EXECUTABLE_PATH_PROPERTY.

NOTE: If the Capability, the $PATH and the System Property are set, the Capability takes priority over the System Property, that in turn takes priority over the $PATH.

Parameters:
desiredCapabilities - Capabilities in which we will look for the path to PhantomJS
docsLink - The link to the PhantomJS documentation page
downloadLink - The link to the PhantomJS download page
Returns:
The driver executable as a File object
Throws:
java.lang.IllegalStateException - If the executable not found or cannot be executed

findGhostDriver

protected static java.io.File findGhostDriver(org.openqa.selenium.Capabilities desiredCapabilities,
                                              java.lang.String docsLink,
                                              java.lang.String downloadLink)
Find the GhostDriver main file (i.e. "main.js").

Looks into the Capabilities and the System Properties for PHANTOMJS_GHOSTDRIVER_PATH_PROPERTY.

NOTE: If both the Capability and the System Property are set, the Capability takes priority.

Parameters:
desiredCapabilities - Capabilities in which we will look for the path to GhostDriver
docsLink - The link to the GhostDriver documentation page
downloadLink - The link to the GhostDriver download page
Returns:
The driver executable as a File object
Throws:
java.lang.IllegalStateException - If the executable not found or cannot be executed