Skip to content

Instantly share code, notes, and snippets.

@stembrain
Last active August 29, 2015 13:56
Show Gist options
  • Save stembrain/9121519 to your computer and use it in GitHub Desktop.
Save stembrain/9121519 to your computer and use it in GitHub Desktop.
How to expose phantomjs default builder so that log location can be modified
/**
* Call this if you need to modify the service before building it, such as
* Builder b = PhantomJsDriverService.createDefaultServiceBuilder(null);
* b.withLogFile(new File("foo.log"));
* b.build();
**/
public static Builder createDefaultServiceBuilder(Capabilities desiredCapabilities){
// Look for Proxy configuration within the Capabilities
Proxy proxy = null;
if (desiredCapabilities != null) {
proxy = Proxies.extractProxy(desiredCapabilities);
}
// Find PhantomJS executable
File phantomjsfile = findPhantomJS(desiredCapabilities, PHANTOMJS_DOC_LINK, PHANTOMJS_DOWNLOAD_LINK);
// Find GhostDriver main JavaScript file
File ghostDriverfile = findGhostDriver(desiredCapabilities, GHOSTDRIVER_DOC_LINK, GHOSTDRIVER_DOWNLOAD_LINK);
// Build & return service
return new Builder().usingPhantomJSExecutable(phantomjsfile)
.usingGhostDriver(ghostDriverfile)
.usingAnyFreePort()
.withProxy(proxy)
.withLogFile(new File(PHANTOMJS_DEFAULT_LOGFILE))
.usingCommandLineArguments(
findCLIArgumentsFromCaps(desiredCapabilities, PHANTOMJS_CLI_ARGS))
.usingGhostDriverCommandLineArguments(
findCLIArgumentsFromCaps(desiredCapabilities, PHANTOMJS_GHOSTDRIVER_CLI_ARGS));
}
/**
* Configures and returns a new {@link PhantomJSDriverService} using the default configuration.
* <p/>
* In this configuration, the service will use the PhantomJS executable identified by the the
* following capability, system property or PATH environment variables:
* <ul>
* <li>{@link PhantomJSDriverService#PHANTOMJS_EXECUTABLE_PATH_PROPERTY}</li>
* <li>
* {@link PhantomJSDriverService#PHANTOMJS_GHOSTDRIVER_PATH_PROPERTY}
* (Optional - without will use GhostDriver internal to PhantomJS)
* </li>
* </ul>
* <p/>
* Each service created by this method will be configured to find and use a free port on the current system.
*
* @return A new ChromeDriverService using the default configuration.
*/
public static PhantomJSDriverService createDefaultService(Capabilities desiredCapabilities) {
return createDefaultServiceBuilder(desiredCapabilities).build();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment