org.openqa.selenium.phantomjs.PhantomJSDriverService Java Examples

The following examples show how to use org.openqa.selenium.phantomjs.PhantomJSDriverService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PhantomJSDriverConfig.java    From jmeter-plugins-webdriver with Apache License 2.0 6 votes vote down vote up
protected Capabilities createCapabilities() {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.PROXY, createProxy());
    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
            getPhantomJsExecutablePath());
    
    if (getPhantomJsCliArgs() != null && getPhantomJsCliArgs().trim().length() > 0) {
    	capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliParamsToStringArray(getPhantomJsCliArgs()));
    }

    if (getPhantomJsGhostdriverCliArgs() != null && getPhantomJsGhostdriverCliArgs().trim().length() > 0) {
    	capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_CLI_ARGS, cliParamsToStringArray(getPhantomJsGhostdriverCliArgs()));
    }
    
    return capabilities;
}
 
Example #2
Source File: WebUITest.java    From blog with MIT License 6 votes vote down vote up
@BeforeClass
public static void startServer() throws ServletException {
	
	// INIT WEB SERVER (TOMCAT)
	server = new EmbeddedServer(8080, "/20150118-test-selenium");
	server.start();

	// INIT WEB BROWSER (SELENIUM + PHANTOMJS)
	driver = new PhantomJSDriver(
	new DesiredCapabilities(ImmutableMap.of( //
			PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, //
			new PhantomJsDownloader().downloadAndExtract()
					.getAbsolutePath())));
	baseUrl = "http://localhost:8080/20150118-test-selenium";
	driver.manage().timeouts().implicitlyWait(5, SECONDS);
}
 
Example #3
Source File: PhantomJSDriverConfigTest.java    From jmeter-plugins-webdriver with Apache License 2.0 5 votes vote down vote up
@Before
public void createConfig() throws IOException {
    config = new PhantomJSDriverConfig();
    config.setPhantomJsExecutablePath(System.getProperty(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY));
    JMeterVariables variables = new JMeterVariables();
    JMeterContextService.getContext().setVariables(variables);
    try {
        config.threadStarted();
    } catch (UnreachableBrowserException ignored) {
        // TODO: mock it properly
    }
}
 
Example #4
Source File: PhantomJsBrowser.java    From SeleniumCucumber with GNU General Public License v3.0 5 votes vote down vote up
public PhantomJSDriverService getPhantomJsService() {
	return new PhantomJSDriverService.Builder()
			.usingAnyFreePort()
			.usingPhantomJSExecutable(
					new File(ResourceHelper
							.getResourcePath("driver/phantomjs.exe")))
			.withLogFile(
					new File(ResourceHelper
							.getResourcePath("logs/phantomjslogs/")
							+ "phantomjslogs"
							+ DateTimeHelper.getCurrentDateTime() + ".log"))
			.build();

}
 
Example #5
Source File: IndexStep.java    From charles-rest with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Use phantomjs to fetch the web content.
 * @return WebDriver.
 */
protected WebDriver phantomJsDriver() {
    String phantomJsExecPath =  System.getProperty("phantomjsExec");
    if(phantomJsExecPath == null || "".equals(phantomJsExecPath)) {
        phantomJsExecPath = "/usr/local/bin/phantomjs";
    }
    DesiredCapabilities dc = new DesiredCapabilities();
    dc.setJavascriptEnabled(true);
    dc.setCapability(
        PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
        phantomJsExecPath
    );
    return new PhantomJSDriver(dc);
}
 
Example #6
Source File: PhantomJsFactory.java    From Asqatasun with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 
 * @param config
 * @return A FirefoxDriver.
 */
@Override
public RemoteWebDriver make(HashMap<String, String> config) {
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setJavascriptEnabled(true);
    if (System.getProperty(PHANTOMJS_PATH_PROPERTY) != null) {
        path = System.getProperty(PHANTOMJS_PATH_PROPERTY);
    }
    caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
                    path);
    return new PhantomJSDriver(caps);
}
 
Example #7
Source File: KeycloakWebDriverConfigurator.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private void configurePhantomJSDriver(WebDriverConfiguration webDriverCfg, DesiredCapabilities capabilitiesToAdd) {
    if (!webDriverCfg.getBrowser().equals("phantomjs")) {
        return;
    }

    String cliArgs = System.getProperty("keycloak.phantomjs.cli.args");

    if (cliArgs == null) {
        cliArgs = "--ignore-ssl-errors=true --web-security=false";
    }

    capabilitiesToAdd.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgs);
}
 
Example #8
Source File: WebUITest.java    From blog with MIT License 5 votes vote down vote up
@Override
public WebDriver getDefaultDriver() {

	// INIT WEB BROWSER (SELENIUM + PHANTOMJS)
	driver = new PhantomJSDriver(new DesiredCapabilities(ImmutableMap.of( //
			PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, //
			new PhantomJsDownloader().downloadAndExtract()
					.getAbsolutePath())));
	baseUrl = "http://localhost:8080/20150125-test-fluentlenium";
	driver.manage().timeouts().implicitlyWait(5, SECONDS);

	return driver;
}
 
Example #9
Source File: SeleniumPhantomjsPageLoader.java    From xxl-crawler with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Document load(PageRequest pageRequest) {
    if (!UrlUtil.isUrl(pageRequest.getUrl())) {
        return null;
    }

    // driver init
    DesiredCapabilities dcaps = new DesiredCapabilities();
    dcaps.setCapability(CapabilityType.ACCEPT_SSL_CERTS, !pageRequest.isValidateTLSCertificates());
    dcaps.setCapability(CapabilityType.TAKES_SCREENSHOT, false);
    dcaps.setCapability(CapabilityType.SUPPORTS_FINDING_BY_CSS, true);
    dcaps.setJavascriptEnabled(true);
    if (driverPath!=null && driverPath.trim().length()>0) {
        dcaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, driverPath);
    }

    if (pageRequest.getProxy() != null) {
        dcaps.setCapability(CapabilityType.ForSeleniumServer.AVOIDING_PROXY, true);
        dcaps.setCapability(CapabilityType.ForSeleniumServer.ONLY_PROXYING_SELENIUM_TRAFFIC, true);
        System.setProperty("http.nonProxyHosts", "localhost");
        dcaps.setCapability(CapabilityType.PROXY, pageRequest.getProxy());
    }

    /*dcaps.setBrowserName(BrowserType.CHROME);
    dcaps.setVersion("70");
    dcaps.setPlatform(Platform.WIN10);*/

    WebDriver webDriver = new PhantomJSDriver(dcaps);

    try {
        // driver run
        webDriver.get(pageRequest.getUrl());

        if (pageRequest.getCookieMap() != null && !pageRequest.getCookieMap().isEmpty()) {
            for (Map.Entry<String, String> item: pageRequest.getCookieMap().entrySet()) {
                webDriver.manage().addCookie(new Cookie(item.getKey(), item.getValue()));
            }
        }

        webDriver.manage().timeouts().implicitlyWait(pageRequest.getTimeoutMillis(), TimeUnit.MILLISECONDS);
        webDriver.manage().timeouts().pageLoadTimeout(pageRequest.getTimeoutMillis(), TimeUnit.MILLISECONDS);
        webDriver.manage().timeouts().setScriptTimeout(pageRequest.getTimeoutMillis(), TimeUnit.MILLISECONDS);

        String pageSource = webDriver.getPageSource();
        if (pageSource != null) {
            Document html = Jsoup.parse(pageSource);
            return html;
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    } finally {
        if (webDriver != null) {
            webDriver.quit();
        }
    }
    return null;
}
 
Example #10
Source File: PhantomJsBrowser.java    From SeleniumCucumber with GNU General Public License v3.0 4 votes vote down vote up
public WebDriver getPhantomJsDriver(PhantomJSDriverService sev,
		Capabilities cap) {

	return new PhantomJSDriver(sev, cap);
}
 
Example #11
Source File: PhantomJsBrowser.java    From SeleniumCucumber with GNU General Public License v3.0 4 votes vote down vote up
public WebDriver getPhantomJsDriver(String hubUrl,PhantomJSDriverService sev,
		Capabilities cap) throws MalformedURLException {

	return new RemoteWebDriver(new URL(hubUrl), cap);
}