Example usage for org.openqa.selenium.chrome ChromeDriver ChromeDriver

List of usage examples for org.openqa.selenium.chrome ChromeDriver ChromeDriver

Introduction

In this page you can find the example usage for org.openqa.selenium.chrome ChromeDriver ChromeDriver.

Prototype

public ChromeDriver() 

Source Link

Document

Creates a new ChromeDriver using the ChromeDriverService#createDefaultService default server configuration.

Usage

From source file:net.atf4j.webdriver.page.BootstrapPageTest.java

License:Open Source License

@Test
public void testInitializr() {
    final WebDriver webDriver = new ChromeDriver();
    assumeNotNull(webDriver);/*w ww  . j av a2s  .  c o m*/
    final BootstrapPage bootstrapPage = new BootstrapPage(webDriver);
    assumeNotNull(bootstrapPage);
    assertNotNull(bootstrapPage.open("http://127.0.0.1:8080/initializr"));
    assertNotNull(bootstrapPage.verify());
    assertNotNull(bootstrapPage.close());
}

From source file:net.atf4j.webdriver.WebDriverSmokeTest.java

License:Open Source License

/**
 * Smoke Test ChromeDriver with Tomcat.//from ww  w . j  a v  a2s.c  om
 */
@Test
public void testChromeTomcat() {
    // TestContext.assumeLocal();
    final WebDriver webDriver = new ChromeDriver();
    verifyNotNull(webDriver);
    verifyTomcatPresent(webDriver);
    webDriver.close();
}

From source file:net.mindengine.galen.browser.SeleniumBrowserFactory.java

License:Apache License

private Browser createLocalBrowser() {
    if (FIREFOX.equals(browserType)) {
        return new SeleniumBrowser(new FirefoxDriver());
    } else if (CHROME.equals(browserType)) {
        return new SeleniumBrowser(new ChromeDriver());
    } else if (IE.equals(browserType)) {
        return new SeleniumBrowser(new InternetExplorerDriver());
    } else if (PHANTOMJS.equals(browserType)) {
        return new SeleniumBrowser(new PhantomJSDriver());
    } else if (SAFARI.equals(browserType)) {
        return new SeleniumBrowser(new SafariDriver());
    } else/*from ww w .j  av a2 s. co  m*/
        throw new RuntimeException(String.format("Unknown browser type: \"%s\"", browserType));
}

From source file:nz.co.testamation.core.WebIntegrationTestAutoConfiguration.java

License:Apache License

@Bean
@Autowired/* www .ja  v  a 2 s . c o m*/
public WebDriver webDriver(@Value("${web.driver:firefox}") String webDriver,
        @Value("${web.driver.autoDownload.mimeTypes:application/pdf}") String autoDownloadMimeTypes,
        @Qualifier("webDriverDownloadDir") File downloadDir) {

    if ("htmlunit".equals(webDriver)) {
        return new HtmlUnitDriver();
    }

    if ("chrome".equals(webDriver)) {
        return new ChromeDriver();
    }

    if ("firefox".equals(webDriver)) {
        FirefoxBinary firefoxBinary = new FirefoxBinary();
        if (System.getenv("DISPLAY") == null) {
            firefoxBinary.setEnvironmentProperty("DISPLAY", ":99");
        }

        FirefoxProfile profile = new FirefoxProfile();

        profile.setPreference("browser.download.folderList", 2); // Download to: 0 desktop, 1 default download location, 2 custom folder
        profile.setPreference("browser.download.dir", downloadDir.getAbsolutePath());
        profile.setPreference("browser.download.manager.showWhenStarting", false);
        profile.setPreference("browser.helperApps.alwaysAsk.force", false);
        profile.setPreference("browser.helperApps.neverAsk.saveToDisk", autoDownloadMimeTypes);
        profile.setPreference("plugin.disable_full_page_plugin_for_types", "application/pdf");
        profile.setPreference("pdfjs.disabled", true);

        return new FirefoxDriver(firefoxBinary, profile);
    }

    if ("ie".equals(webDriver)) {
        return new InternetExplorerDriver();
    }

    if ("safari".equals(webDriver)) {
        return new SafariDriver();
    }

    if ("opera".equals(webDriver)) {
        return new OperaDriver();
    }

    throw new IllegalArgumentException(format("Web driver %s not supported.", webDriver));
}

From source file:okw.gui.adapter.selenium.SeDriver.java

License:Open Source License

public void DriveChrome() {
    this.driver = new ChromeDriver();
}

From source file:oop.appengine.modules.test.selenium.WebDriverFactory.java

License:Apache License

/**
 * ?driverName??WebDriver./* w ww  .j a  va  2  s. co m*/
 * 
 * ??firefox,ie,chrome??.
 * 
 * ??????HtmlUnit.
 * 
 * ????Windows, IE?XWindows, ???remote driverWindows.
 * drivernameremote:192.168.0.2:4444:firefox, ??http://192.168.0.2:4444/wd/hub?selenium remote?.
 */
public static WebDriver createDriver(String driverName) {
    WebDriver driver = null;

    if (BrowserType.firefox.name().equals(driverName)) {
        driver = new FirefoxDriver();
    } else if (BrowserType.ie.name().equals(driverName)) {
        driver = new InternetExplorerDriver();
    } else if (BrowserType.chrome.name().equals(driverName)) {
        driver = new ChromeDriver();
    } else if (BrowserType.htmlunit.name().equals(driverName)) {
        driver = new HtmlUnitDriver(true);
    } else if (driverName.startsWith(BrowserType.remote.name())) {
        String[] params = driverName.split(":");
        Assert.isTrue(params.length == 4,
                "Remote driver is not right, accept format is \"remote:localhost:4444:firefox\", but the input is\""
                        + driverName + "\"");

        String remoteHost = params[1];
        String remotePort = params[2];
        String driverType = params[3];

        String remoteUrl = "http://" + remoteHost + ":" + remotePort + "/wd/hub";

        DesiredCapabilities cap = null;
        if (BrowserType.firefox.name().equals(driverType)) {
            cap = DesiredCapabilities.firefox();
        } else if (BrowserType.ie.name().equals(driverType)) {
            cap = DesiredCapabilities.internetExplorer();
        } else if (BrowserType.chrome.name().equals(driverType)) {
            cap = DesiredCapabilities.chrome();
        }

        try {
            driver = new RemoteWebDriver(new URL(remoteUrl), cap);
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
    }

    Assert.notNull(driver, "Driver could be found by name:" + driverName);

    return driver;
}

From source file:org.apache.archiva.web.test.WebDriverBrowseTest.java

License:Apache License

@Override
public WebDriver getDefaultDriver() {
    String seleniumBrowser = System.getProperty("selenium.browser");

    if (StringUtils.contains(seleniumBrowser, "chrome")) {
        return new ChromeDriver();
    }/*from   w  w w .  j  a va 2  s  . c om*/

    if (StringUtils.contains(seleniumBrowser, "safari")) {
        return new SafariDriver();
    }

    if (StringUtils.contains(seleniumBrowser, "iexplore")) {
        return new InternetExplorerDriver();
    }

    return new FirefoxDriver();

}

From source file:org.apache.directory.fortress.web.integration.FortressWebSeleniumITCase.java

License:Apache License

@Before
public void setupTest() {
    if (driverType.equals(DriverType.CHROME)) {
        driver = new ChromeDriver();
    } else {//  www . j  ava2 s .c o m
        driver = new FirefoxDriver();
    }
    driver.manage().window().maximize();
}

From source file:org.apache.tomcat.maven.webapp.test.SimpleTest.java

License:Apache License

@Test
public void testHelloWorld() throws InterruptedException {
    String serverUrl = System.getProperty("serverUrl");
    assertNotNull(serverUrl, "serverUrl was not found");

    WebDriver driver = new ChromeDriver();
    driver.get(serverUrl);/*from  w  w w  .j av  a 2  s . com*/
    //      driver.get("http://localhost:8080/");

    WebDriverWait wait = new WebDriverWait(driver, 5);
    wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("who"))));

    driver.findElement(By.id("who")).sendKeys("Hello World!");
    driver.findElement(By.id("send-btn")).click();

    wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("response"))));

    assertEquals("Unexpected response", "Hello Hello World!", driver.findElement(By.id("response")).getText());
    driver.quit();
}

From source file:org.apache.zeppelin.WebDriverManager.java

License:Apache License

public static WebDriver getWebDriver() {
    WebDriver driver = null;/*from   ww  w.j  a va2  s. c o m*/

    if (driver == null) {
        try {
            FirefoxBinary ffox = new FirefoxBinary();
            if ("true".equals(System.getenv("TRAVIS"))) {
                ffox.setEnvironmentProperty("DISPLAY", ":99"); // xvfb is supposed to
                // run with DISPLAY 99
            }
            int firefoxVersion = WebDriverManager.getFirefoxVersion();
            LOG.info("Firefox version " + firefoxVersion + " detected");

            downLoadsDir = FileUtils.getTempDirectory().toString();

            String tempPath = downLoadsDir + "/firefox/";

            downloadGeekoDriver(firefoxVersion, tempPath);

            FirefoxProfile profile = new FirefoxProfile();
            profile.setPreference("browser.download.folderList", 2);
            profile.setPreference("browser.download.dir", downLoadsDir);
            profile.setPreference("browser.helperApps.alwaysAsk.force", false);
            profile.setPreference("browser.download.manager.showWhenStarting", false);
            profile.setPreference("browser.download.manager.showAlertOnComplete", false);
            profile.setPreference("browser.download.manager.closeWhenDone", true);
            profile.setPreference("app.update.auto", false);
            profile.setPreference("app.update.enabled", false);
            profile.setPreference("dom.max_script_run_time", 0);
            profile.setPreference("dom.max_chrome_script_run_time", 0);
            profile.setPreference("browser.helperApps.neverAsk.saveToDisk",
                    "application/x-ustar,application/octet-stream,application/zip,text/csv,text/plain");
            profile.setPreference("network.proxy.type", 0);

            System.setProperty(GeckoDriverService.GECKO_DRIVER_EXE_PROPERTY, tempPath + "geckodriver");
            System.setProperty(SystemProperty.DRIVER_USE_MARIONETTE, "false");

            FirefoxOptions firefoxOptions = new FirefoxOptions();
            firefoxOptions.setBinary(ffox);
            firefoxOptions.setProfile(profile);
            driver = new FirefoxDriver(firefoxOptions);
        } catch (Exception e) {
            LOG.error("Exception in WebDriverManager while FireFox Driver ", e);
        }
    }

    if (driver == null) {
        try {
            driver = new ChromeDriver();
        } catch (Exception e) {
            LOG.error("Exception in WebDriverManager while ChromeDriver ", e);
        }
    }

    if (driver == null) {
        try {
            driver = new SafariDriver();
        } catch (Exception e) {
            LOG.error("Exception in WebDriverManager while SafariDriver ", e);
        }
    }

    String url;
    if (System.getenv("url") != null) {
        url = System.getenv("url");
    } else {
        url = "http://localhost:8080";
    }

    long start = System.currentTimeMillis();
    boolean loaded = false;
    driver.manage().timeouts().implicitlyWait(AbstractZeppelinIT.MAX_IMPLICIT_WAIT, TimeUnit.SECONDS);
    driver.get(url);

    while (System.currentTimeMillis() - start < 60 * 1000) {
        // wait for page load
        try {
            (new WebDriverWait(driver, 30)).until(new ExpectedCondition<Boolean>() {
                @Override
                public Boolean apply(WebDriver d) {
                    return d.findElement(By.xpath("//i[@uib-tooltip='WebSocket Connected']")).isDisplayed();
                }
            });
            loaded = true;
            break;
        } catch (TimeoutException e) {
            LOG.info("Exception in WebDriverManager while WebDriverWait ", e);
            driver.navigate().to(url);
        }
    }

    if (loaded == false) {
        fail();
    }

    driver.manage().window().maximize();
    return driver;
}