Java Code Examples for PhantomJSDriverService
Example 1
Project: thucydides File: PhantomJSCapabilityEnhancer.java View source code | Vote up | 6 votes |
public void enhanceCapabilities(DesiredCapabilities capabilities) {
if (environmentVariables.getProperty(ThucydidesSystemProperty.PHANTOMJS_BINARY_PATH) != null) {
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
environmentVariables.getProperty(ThucydidesSystemProperty.PHANTOMJS_BINARY_PATH));
}
ArrayList<String> cliArgs = Lists.newArrayList();
setSecurityOptions(cliArgs);
setLoggingOptions(cliArgs);
if (StringUtils.isNotEmpty(ThucydidesSystemProperty.THUCYDIDES_PROXY_HTTP.from(environmentVariables))) {
setProxyOptions(cliArgs);
}
if (StringUtils.isNotEmpty(ThucydidesSystemProperty.WEBDRIVER_REMOTE_URL.from(environmentVariables))) {
setRemoteOptions(cliArgs);
}
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgs.toArray(new String[]{}));
}
Example 2
Project: seauto File: AbstractConfigurableDriverProvider.java View source code | Vote up | 6 votes |
/**
* Default implementation throws UnsupportedOperationException
*/
protected WebDriver getPhantomJsWebDriver()
{
String pathToBin = getOsSpecificBinaryPathFromProp(PHANTOM_JS_BIN_PROP, "phantomjs");
DesiredCapabilities capabilities = getPhantomJsCapabilities();
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, pathToBin);
return new PhantomJSDriver(capabilities);
}
Example 3
Project: serenity-core File: PhantomJSCapabilityEnhancer.java View source code | Vote up | 6 votes |
public void enhanceCapabilities(DesiredCapabilities capabilities) {
if (environmentVariables.getProperty(ThucydidesSystemProperty.PHANTOMJS_BINARY_PATH) != null) {
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
environmentVariables.getProperty(ThucydidesSystemProperty.PHANTOMJS_BINARY_PATH));
}
ArrayList<String> cliArgs = Lists.newArrayList();
setSecurityOptions(cliArgs);
setLoggingOptions(cliArgs);
if (StringUtils.isNotEmpty(ThucydidesSystemProperty.THUCYDIDES_PROXY_HTTP.from(environmentVariables))) {
setProxyOptions(cliArgs);
}
if (StringUtils.isNotEmpty(ThucydidesSystemProperty.WEBDRIVER_REMOTE_URL.from(environmentVariables))) {
setRemoteOptions(cliArgs);
}
if (StringUtils.isNotEmpty(ThucydidesSystemProperty.PHANTOMJS_SSL_PROTOCOL.from(environmentVariables))) {
String sslSupport = ThucydidesSystemProperty.PHANTOMJS_SSL_PROTOCOL.from(environmentVariables);
if (sslSupport.equals("sslv2") ||
sslSupport.equals("sslv3") ||
sslSupport.equals("tlsv1") ||
sslSupport.equals("any")) {
cliArgs.add("--ssl-protocol=" + sslSupport);
}
else {
cliArgs.add("--ssl-protocol=any");
}
}
else {
cliArgs.add("--ssl-protocol=any");
}
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgs.toArray(new String[]{}));
}
Example 4
Project: ya.blogo File: PhantomJSRule.java View source code | Vote up | 6 votes |
@Override
public void before() {
File phantomjs = Phanbedder.unpack();
DesiredCapabilities dcaps = new DesiredCapabilities();
dcaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, phantomjs.getAbsolutePath());
driver = new PhantomJSDriver(dcaps);
}
Example 5
Project: dextranet File: TesteFuncionalBase.java View source code | Vote up | 6 votes |
@BeforeClass
public static void setup() {
server.enableAuthentication(true, false);
server.enableJetty(8080);
TesteIntegracaoBase.setup();
String executable = "";
if (isWindows()) {
executable = "target/phantomjs/phantomjs.exe";
} else {
executable = "target/phantomjs/phantomjs";
}
DesiredCapabilities dCaps = new DesiredCapabilities();
dCaps.setJavascriptEnabled(true);
dCaps.setCapability("takesScreenshot", false);
dCaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, executable);
driver = new PhantomJSDriver(dCaps);
driver.manage().window().setSize(new Dimension(1600, 900));
}
Example 6
Project: seleniumQuery File: PhantomJSDriverBuilderTest.java View source code | Vote up | 6 votes |
@Test
public void withCapabilities() {
// given
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_PAGE_SETTINGS_PREFIX+"userAgent", "JustAnotherAgent");
// when
$.driver().usePhantomJS().withCapabilities(capabilities);
// then
$.url(classNameToTestFileUrl(SeleniumQueryBrowserTest.class));
assertThat($("#agent").html(), containsString("JustAnotherAgent"));
}
Example 7
Project: XBDD File: XbddDriver.java View source code | Vote up | 6 votes |
private static WebDriver getPhantomJsDriver() {
final DesiredCapabilities caps = DesiredCapabilities.phantomjs();
caps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS,
new String[] { "--ignore-ssl-errors=true", "--ssl-protocol=tlsv1", "--web-security=false" });
final PhantomJSDriver phantomJSDriver = new PhantomJSDriver(caps);
phantomJSDriver.manage().window().setSize(new Dimension(1280, 800));
return phantomJSDriver;
}
Example 8
Project: nitrogen File: NitrogenPhantomJsDriver.java View source code | Vote up | 6 votes |
private static DesiredCapabilities initBrowserCapabilities() {
DesiredCapabilities browserCapabilities = new DesiredCapabilities();
browserCapabilities.setJavascriptEnabled(true);
if (StringUtils.isNotEmpty(PHANTOM_JS_PATH_PROP)) {
System.out.printf("\n\nSetting Phantom JS path to %s\n\n%n", PHANTOM_JS_PATH_PROP);
browserCapabilities.setCapability(
PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
PHANTOM_JS_PATH_PROP);
}
browserCapabilities.setCapability("takesScreenshot", true);
browserCapabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, buildPhantomJsCommandLineArguments());
browserCapabilities.setCapability(PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_CLI_ARGS, new String[]{
formatArgument(LOG_LEVEL_ARG, ERROR)
});
return browserCapabilities;
}
Example 9
Project: crawljax File: WebDriverBrowserBuilder.java View source code | Vote up | 6 votes |
private EmbeddedBrowser newPhantomJSDriver(ImmutableSortedSet<String> filterAttributes,
long crawlWaitReload, long crawlWaitEvent) {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("takesScreenshot", true);
caps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new String[]{"--webdriver-loglevel=WARN"});
final ProxyConfiguration proxyConf = configuration
.getProxyConfiguration();
if (proxyConf != null && proxyConf.getType() != ProxyType.NOTHING) {
final String proxyAddrCap = "--proxy=" + proxyConf.getHostname()
+ ":" + proxyConf.getPort();
final String proxyTypeCap = "--proxy-type=http";
final String[] args = new String[] { proxyAddrCap, proxyTypeCap };
caps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, args);
}
PhantomJSDriver phantomJsDriver = new PhantomJSDriver(caps);
return WebDriverBackedEmbeddedBrowser.withDriver(phantomJsDriver, filterAttributes,
crawlWaitEvent, crawlWaitReload);
}
Example 10
Project: handytrowel File: HTMLFetcher.java View source code | Vote up | 6 votes |
public String getPageSource(final String url) throws TimeoutException {
// Make the Selenium WebDriver logs be quiet
phantomJsLogger.setLevel(Level.OFF);
DesiredCapabilities desiredCapabilities = DesiredCapabilities.phantomjs();
// What other CLI args there are: http://phantomjs.org/api/command-line.html
// Where the cache goes on Mac OS X: ~/Library/Application\ Support/Ofi\ Labs/PhantomJS/
// Other cache locations: https://groups.google.com/forum/#!topic/phantomjs/8GYaXKmowj0
desiredCapabilities.setCapability(
PhantomJSDriverService.PHANTOMJS_CLI_ARGS,
new String[] {"--ignore-ssl-errors=yes", "--load-images=no",
"--disk-cache=true", "--max-disk-cache-size=size=51200"
});
final WebDriver driver = new PhantomJSDriver(desiredCapabilities);
// doesn't work, keep as reference.
//driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
try {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
driver.get(url);
}
});
t.start();
try {
t.join(timeoutMillis);
} catch (InterruptedException e) {
}
if (t.isAlive()) {
System.out.println("Timeout for HTTP GET to: " + url);
t.interrupt();
throw new TimeoutException();
}
String pageSource = driver.getPageSource();
return pageSource;
} finally {
driver.quit();
}
}
Example 11
Project: adf-selenium File: PhantomJSDriverResource.java View source code | Vote up | 6 votes |
@Override
protected RemoteWebDriver createDriver(String language) {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(PhantomJSDriverService.PHANTOMJS_PAGE_CUSTOMHEADERS_PREFIX + "Accept-Language", language);
PhantomJSDriver retval = new PhantomJSDriver(caps);
return retval;
}
Example 12
Project: Web-snapshot File: SnapshotCreatorImpl.java View source code | Vote up | 6 votes |
/**
*
* @return
*/
private RemoteWebDriver getWebDriver(int windowWidth, int windowHeight, String webDriver) {
RemoteWebDriver driver;
if (webDriver.equals(FIREFOX_BROWSER_NAME)) {
driver = new FirefoxDriver(new FirefoxBinary(new File(firefoxBinaryPath)), new FirefoxProfile());
} else {
DesiredCapabilities caps = DesiredCapabilities.phantomjs();
caps.setCapability(
PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
phantomJsBinaryPath);
driver = new PhantomJSDriver(caps);
}
driver.manage().window().setSize(new Dimension(windowWidth, windowHeight));
return driver;
}
Example 13
Project: burp-csj File: SetupCrawljax.java View source code | Vote up | 6 votes |
private EmbeddedBrowser newPhantomBrowser() {
String phantompath = CrawlPanel.phatomjslocation.getText();
File file = new File(phantompath);
DesiredCapabilities capability = new DesiredCapabilities();
capability.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, file.getAbsolutePath());
if (CrawlPanel.manualproxy.isSelected()) {
String host = CrawlPanel.HostProxy.getText();
Integer port = Integer.parseInt(CrawlPanel.PortProxy.getText());
String PROXY = host + ":" + port;
org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
proxy.setHttpProxy(PROXY).setFtpProxy(PROXY).setSslProxy(PROXY);
capability.setCapability(CapabilityType.PROXY, proxy);
}
capability.setCapability("takesScreenshot", false);
String[] args = {"--ignore-ssl-errors=yes"};
capability.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, args);
capability.setCapability("phantomjs.page.settings.userAgent", "Mozilla/5.0 (Windows NT 5.1; rv:22.0) Gecko/20100101 Firefox/22.0");
//System.out.println("Capability:" +capability);
WebDriver drivertest = null;
try {
drivertest = new PhantomJSDriver(capability);
} catch (Throwable e) {
JOptionPane.showMessageDialog(null, "PhantomJS Location not specified");
CrawlPanel.Browser.setSelectedItem("Firefox");
}
if (CrawlPanel