Search in sources :

Example 1 with ChromeDriver

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();
}
Also used : WebDriver(org.openqa.selenium.WebDriver) HashMap(java.util.HashMap) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) WebElement(org.openqa.selenium.WebElement) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with ChromeDriver

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());
}
Also used : UnsupportedBrowserException(ru.sbtqa.tag.pagefactory.exceptions.UnsupportedBrowserException) Proxy(org.openqa.selenium.Proxy) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) WebDriverCapabilitiesParser(ru.sbtqa.tag.pagefactory.support.capabilities.WebDriverCapabilitiesParser) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) SafariDriver(org.openqa.selenium.safari.SafariDriver)

Example 3 with ChromeDriver

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;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) PhantomJSDriver(org.openqa.selenium.phantomjs.PhantomJSDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver)

Example 4 with ChromeDriver

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;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriverService(org.openqa.selenium.chrome.ChromeDriverService) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) Map(java.util.Map)

Example 5 with ChromeDriver

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));
}
Also used : ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver)

Aggregations

ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)98 ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)47 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)39 File (java.io.File)33 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)27 WebDriver (org.openqa.selenium.WebDriver)25 HashMap (java.util.HashMap)24 Before (org.junit.Before)15 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)13 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)13 URL (java.net.URL)12 InternetExplorerDriver (org.openqa.selenium.ie.InternetExplorerDriver)12 Test (org.junit.Test)10 ChromeDriverService (org.openqa.selenium.chrome.ChromeDriverService)10 FirefoxProfile (org.openqa.selenium.firefox.FirefoxProfile)10 HtmlUnitDriver (org.openqa.selenium.htmlunit.HtmlUnitDriver)9 Actions (org.openqa.selenium.interactions.Actions)9 PhantomJSDriver (org.openqa.selenium.phantomjs.PhantomJSDriver)9 BeforeClass (org.junit.BeforeClass)7 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)7