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:org.xwiki.test.ui.WebDriverFactory.java

License:Open Source License

public WebDriver createWebDriver(String browserName) {
    WebDriver driver;//from  ww  w. ja v  a 2s. co m
    if (browserName.startsWith("*firefox")) {
        // Native events are disabled by default for Firefox on Linux as it may cause tests which open many windows
        // in parallel to be unreliable. However, native events work quite well otherwise and are essential for some
        // of the new actions of the Advanced User Interaction. We need native events to be enable especially for
        // testing the WYSIWYG editor. See http://code.google.com/p/selenium/issues/detail?id=2331 .
        FirefoxProfile profile = new FirefoxProfile();
        profile.setEnableNativeEvents(true);
        // Make sure Firefox doesn't upgrade automatically on CI agents.
        profile.setPreference("app.update.auto", false);
        profile.setPreference("app.update.enabled", false);
        profile.setPreference("app.update.silent", false);
        driver = new FirefoxDriver(profile);

        // Hide the Add-on bar (from the bottom of the window, with "WebDriver" written on the right) because it can
        // prevent buttons or links from being clicked when they are beneath it and native events are used.
        // See https://groups.google.com/forum/#!msg/selenium-users/gBozOynEjs8/XDxxQNmUSCsJ
        // We need to load a page before sending the keys otherwise WebDriver throws ElementNotVisible exception.
        driver.get("data:text/plain;charset=utf-8,XWiki");
        driver.switchTo().activeElement().sendKeys(Keys.chord(Keys.CONTROL, "/"));
    } else if (browserName.startsWith("*iexplore")) {
        driver = new InternetExplorerDriver();
    } else if (browserName.startsWith("*chrome")) {
        driver = new ChromeDriver();
    } else if (browserName.startsWith("*phantomjs")) {
        DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
        capabilities.setCapability("handlesAlerts", true);
        try {
            driver = new PhantomJSDriver(ResolvingPhantomJSDriverService.createDefaultService(), capabilities);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    } else {
        throw new RuntimeException("Unsupported browser name [" + browserName + "]");
    }

    // Maximize the browser window by default so that the page has a standard layout. Individual tests can resize
    // the browser window if they want to test how the page layout adapts to limited space. This reduces the
    // probability of a test failure caused by an unexpected layout (nested scroll bars, floating menu over links
    // and buttons and so on).
    driver.manage().window().maximize();

    return driver;
}

From source file:org.zaproxy.zap.extension.spiderAjax.ExtensionAjax.java

License:Apache License

/**
 * This method checks if the chromedriver is available
 * @return true if available, false otherwise.
 *///ww w.  ja v  a 2s  . c  o  m
public boolean isChromeAvail() {
    try {
        new ChromeDriver().quit();
    } catch (Exception e) {
        logger.error(e);
        return false;
    }
    return true;
}

From source file:org.zaproxy.zap.extension.spiderAjax.ProxyAjax.java

License:Apache License

/**
 * This method checks if the chromedriver is available
 * @return true if available, false otherwise.
 *//*from w  w w. ja  v a 2 s  .  c  o  m*/
public boolean isChromeAvail() {
    try {
        new ChromeDriver().close();
    } catch (Exception e) {
        logger.error(e);
        return false;
    }
    return true;
}

From source file:pagelyzer.BrowserRep.java

License:Open Source License

/**
 * Set the selenium driver as local (webdriver instance)
 *//*  www. ja  v a2s .  co m*/
public void setLocalDriver() {
    switch (this.desc) {
    case "firefox":
        FirefoxProfile profile = new FirefoxProfile();
        profile.setPreference("browser.download.lastDir", "/home/sanojaa/src/migration425/sources/inbox/pages");
        profile.setPreference("browser.download.manager.showWhenStarting", false);
        profile.setPreference("browser.download.dir", "/home/sanojaa/src/migration425/sources/inbox/pages");
        profile.setEnableNativeEvents(true);
        this.driver = new FirefoxDriver(profile);
        break;
    case "iexplorer":
        this.driver = new InternetExplorerDriver();
        break;
    case "chrome":
        this.driver = new ChromeDriver();
        break;
    case "opera":
        this.driver = new OperaDriver();
        break;
    case "htmlunit":
        this.driver = new HtmlUnitDriver();
        break;
    }
    setJSDriver();
    this.driver.manage().timeouts().pageLoadTimeout(MAX_WAIT_S, TimeUnit.SECONDS);
    this.driver.manage().timeouts().implicitlyWait(MAX_WAIT_S, TimeUnit.SECONDS);
}

From source file:pt.fccn.saw.selenium.WebDriverTestBase.java

License:Open Source License

/**
 * Creates a Local WebDriver given a string with the web browser name.
 * // ww  w.j  a v  a  2s . co m
 * @param browser The browser name for the WebDriver initialization
 * @return The initialized Local WebDriver
 */
private static WebDriver selectLocalBrowser(String browser) throws java.net.MalformedURLException {
    WebDriver driver = null;
    if (browser.contains("firefox")) {
        driver = new FirefoxDriver();
    } else if (browser.contains("iexplorer")) {
        driver = new InternetExplorerDriver();
    } else if (browser.contains("chrome")) {
        //DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        //capabilities.setCapability("chrome.binary", "/usr/lib/chromium-browser/chromium-browser");
        //driver = new ChromeDriver(capabilities);
        driver = new ChromeDriver();
    } else if (browser.contains("opera")) {
        driver = new OperaDriver();
    } else if (browser.contains("remote-chrome")) {
        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
    } else if (browser.contains("remote-firefox")) {
        DesiredCapabilities capabilities = DesiredCapabilities.firefox();
        driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
        driver.get("http://www.google.com");
    } else {
        // OH NOEZ! I DOAN HAZ DAT BROWSR!
        System.err.println("Cannot find suitable browser driver for [" + browser + "]");
    }
    return driver;
}

From source file:refAppTester.Testeri.java

/**
 * @param args the command line arguments
 *//* w w w  .  j a v  a 2  s . c  om*/
public static void main(String[] args) {
    // Voitaisiin periaatteessa rakentaa tnne testaus? Tehtiin kuitenkin testiluokkaan testit selkeyden vuoksi.
    WebDriver driver = new ChromeDriver();
    driver.get("http://localhost:8080");

    sleep(2);

    WebElement element = driver.findElement(By.linkText("Tallennetut viitteet"));
    element.click();
    sleep(3);
}

From source file:ru.sunflower.selenium.test.SeleniumTests.java

@BeforeClass
public static void setUpClass() {
    //driver = new FirefoxDriver();
    //driver = new PhantomJSDriver();
    driver = new ChromeDriver();
    //driver = new SafariDriver();
}

From source file:ryoji.selenium.AppTest.java

@Before
public void setUp() throws Exception {
    this.driver = new ChromeDriver();
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

From source file:scraper.ScraperUtil.java

protected void getWebpage() throws InterruptedException {
    System.setProperty("webdriver.chrome.driver", "/Users/Whip/data/jars/chromedriver");
    driver = new ChromeDriver();
    System.out.println("UHh");
    driver.get("http://railroadbackdrops.com/category/all");

}

From source file:SearchTest.SearchTest.java

@Before
public void setup() {
    driver = new ChromeDriver();
    driver.get("http://store.demoqa.com");

}