use of org.openqa.selenium.chrome.ChromeDriver in project webmagic by code4craft.
the class SeleniumTest method testSelenium.
@Ignore("need chrome driver")
@Test
public void testSelenium() {
System.getProperties().setProperty("webdriver.chrome.driver", "/Users/yihua/Downloads/chromedriver");
Map<String, Object> contentSettings = new HashMap<String, Object>();
contentSettings.put("images", 2);
Map<String, Object> preferences = new HashMap<String, Object>();
preferences.put("profile.default_content_settings", contentSettings);
DesiredCapabilities caps = DesiredCapabilities.chrome();
caps.setCapability("chrome.prefs", preferences);
caps.setCapability("chrome.switches", Arrays.asList("--user-data-dir=/Users/yihua/temp/chrome"));
WebDriver webDriver = new ChromeDriver(caps);
webDriver.get("http://huaban.com/");
WebElement webElement = webDriver.findElement(By.xpath("/html"));
System.out.println(webElement.getAttribute("outerHTML"));
webDriver.close();
}
use of org.openqa.selenium.chrome.ChromeDriver in project page-factory-2 by sbtqa.
the class TagWebDriver method createDriver.
private static void createDriver() throws UnsupportedBrowserException, MalformedURLException {
DesiredCapabilities capabilities = new WebDriverCapabilitiesParser().parse();
if (!PROPERTIES.getProxy().isEmpty()) {
Proxy seleniumProxy = ProxyConfigurator.configureProxy();
capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
}
String browserName = getBrowserName();
capabilities.setBrowserName(browserName);
String webDriverUrl = PROPERTIES.getWebDriverUrl();
if (!webDriverUrl.isEmpty()) {
setWebDriver(createRemoteWebDriver(webDriverUrl, capabilities));
} else {
if (browserName.equalsIgnoreCase(FIREFOX)) {
setWebDriver(new FirefoxDriver(capabilities));
} else if (browserName.equalsIgnoreCase(SAFARI)) {
setWebDriver(new SafariDriver(capabilities));
} else if (browserName.equalsIgnoreCase(CHROME)) {
WebDriverManagerConfigurator.configureDriver(ChromeDriverManager.getInstance(), CHROME);
setWebDriver(new ChromeDriver(capabilities));
} else if (browserName.equalsIgnoreCase(IE)) {
WebDriverManagerConfigurator.configureDriver(InternetExplorerDriverManager.getInstance(), IE);
setWebDriver(new InternetExplorerDriver(capabilities));
} else {
throw new UnsupportedBrowserException("'" + browserName + "' is not supported yet");
}
}
webDriver.manage().timeouts().pageLoadTimeout(PageFactory.getTimeOutInSeconds(), TimeUnit.SECONDS);
setBrowserSize();
webDriver.get(PROPERTIES.getStartingUrl());
}
use of org.openqa.selenium.chrome.ChromeDriver in project jlineup by otto-de.
the class BrowserUtils method getWebDriverByConfig.
synchronized WebDriver getWebDriverByConfig(Config config, int width) {
WebDriver driver;
switch(config.browser) {
case FIREFOX:
FirefoxDriverManager.getInstance().setup();
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setProfile(getFirefoxProfileWithDisabledAnimatedGifs());
driver = new FirefoxDriver(firefoxOptions);
break;
case FIREFOX_HEADLESS:
FirefoxDriverManager.getInstance().setup();
FirefoxOptions firefoxOptionsForHeadless = new FirefoxOptions();
// Headless parameter is supported with Firefox >= 55
firefoxOptionsForHeadless.addArguments("--headless");
firefoxOptionsForHeadless.addArguments("-width", width + "", "-height", config.windowHeight + "");
firefoxOptionsForHeadless.setProfile(getFirefoxProfileWithDisabledAnimatedGifs());
driver = new FirefoxDriver(firefoxOptionsForHeadless);
break;
case CHROME:
ChromeDriverManager.getInstance().setup();
ChromeOptions options = new ChromeOptions();
// To work in a headless env, this is needed
options.addArguments("--no-sandbox");
driver = new ChromeDriver(options);
break;
case CHROME_HEADLESS:
ChromeDriverManager.getInstance().setup();
ChromeOptions options_headless = new ChromeOptions();
// To work in a headless env, this is needed
options_headless.addArguments("--no-sandbox", "--headless", "--disable-gpu");
options_headless.addArguments("--window-size=" + width + "," + config.windowHeight);
driver = new ChromeDriver(options_headless);
break;
case PHANTOMJS:
default:
PhantomJsDriverManager.getInstance().setup();
driver = new PhantomJSDriver();
break;
}
driver.manage().timeouts().pageLoadTimeout(config.pageLoadTimeout, TimeUnit.SECONDS);
return driver;
}
use of org.openqa.selenium.chrome.ChromeDriver in project activityinfo by bedatadriven.
the class ChromeWebDriverProvider method initPool.
private static WebDriverPool initPool() {
WebDriverPool pool = new WebDriverPool();
// pool.setMaxTotalSize(3);
pool.setCreator(new Function<BrowserProfile, WebDriver>() {
@Override
public WebDriver apply(BrowserProfile input) {
// Start a local http proxy that we can use to control the
// the connection's properties
// ProxyController proxyController = new ProxyController();
// proxyController.start();
Map<String, String> environment = Maps.newHashMap();
if (!Strings.isNullOrEmpty(System.getProperty("browserTimezone"))) {
environment.put("TZ", System.getProperty("browserTimezone"));
}
ChromeDriverService service = new ChromeDriverService.Builder().usingAnyFreePort().usingDriverExecutable(findDriverBin()).withEnvironment(environment).build();
ChromeOptions options = new ChromeOptions();
options.addArguments("--verbose");
//
DesiredCapabilities capabilities = new DesiredCapabilities();
// capabilities.setCapability(CapabilityType.PROXY, proxyController.getWebDriverProxy());
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
// return new ProxiedWebDriver(new ChromeDriver(capabilities), proxyController);
return new ChromeDriver(service, capabilities);
}
});
return pool;
}
use of org.openqa.selenium.chrome.ChromeDriver in project ifml2php by Dipiert.
the class Form_test method loadChromeDriver.
private void loadChromeDriver() {
System.setProperty("webdriver.chrome.driver", "drivers/chromedriver");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--no-sandbox");
drivers.add(new ChromeDriver(chromeOptions));
}
Aggregations