*/
public class PhantomJSDriverFactory extends WebDriverFactory {
@Override
public WebDriver newInstance(DriverOptions driverOptions) {
DesiredCapabilities caps = setupProxy(DesiredCapabilities.phantomjs(), driverOptions);
if (driverOptions.has(PHANTOMJS)) {
File binary = new File(driverOptions.get(PHANTOMJS));
if (!binary.canExecute())
throw new IllegalArgumentException("Missing PhantomJS binary: " + binary);
caps.setCapability(PHANTOMJS_EXECUTABLE_PATH_PROPERTY, binary.getPath());
}
caps.merge(driverOptions.getCapabilities());
if (driverOptions.has(CLI_ARGS)) {
Object cliArgs = caps.getCapability(PHANTOMJS_CLI_ARGS);
if (cliArgs == null) {
cliArgs = ArrayUtils.EMPTY_STRING_ARRAY;
} else {
if (cliArgs instanceof String)
cliArgs = new String[] { (String) cliArgs };
else if (!(cliArgs instanceof String[]))
throw new IllegalArgumentException("Invalid " + PHANTOMJS_CLI_ARGS + ": " + cliArgs);
}
cliArgs = ArrayUtils.addAll((String[]) cliArgs, driverOptions.getCliArgs());
caps.setCapability(PHANTOMJS_CLI_ARGS, cliArgs);
}
PhantomJSDriverService service = CustomPhantomJSDriverServiceFactory.createDefaultService(caps);
PhantomJSDriver driver = new PhantomJSDriver(service, caps);
setInitialWindowSize(driver, driverOptions);
return driver;