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(ChromeOptions options) 

Source Link

Document

Creates a new ChromeDriver instance with the specified options.

Usage

From source file:com.ggasoftware.uitest.utils.WebDriverWrapper.java

License:Open Source License

/**
 * initialization ChromeDriver/*  w  w  w  .ja  v a 2 s  .c  o m*/
 *
 * @param capabilities - desired capabilities
 */
public static void initChromeDriver(Capabilities capabilities) {
    ReporterNGExt.logTechnical("Initialization Chrome Driver");
    setWebDriver(new ChromeDriver(capabilities));
    setTimeout(TIMEOUT);
    getDriver().manage().window().maximize();
}

From source file:com.ggasoftware.uitest.utils.WebDriverWrapper.java

License:Open Source License

/**
 * initialization ChromeDriver/* w ww  .  j a v  a  2s  . c  o m*/
 */
public static void initChromeDriver() {
    ReporterNGExt.logTechnical("Initialization Chrome Driver");
    ChromeOptions options = new ChromeOptions();
    options.addArguments(Arrays.asList("--start-maximized", "--test-type", "--ignore-certificate-errors",
            "--disable-popup-blocking", "--allow-running-insecure-content", "--disable-translate",
            "--always-authorize-plugins"));
    setWebDriver(new ChromeDriver(options));
    setTimeout(TIMEOUT);
}

From source file:com.github.jjYBdx4IL.test.selenium.SeleniumTestBaseTest.java

License:Apache License

public static WebDriver getDriver() {
    if (driver == null) {
        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.setBinary("/usr/bin/chromium-browser");
        driver = new ChromeDriver(chromeOptions);
    }//from   ww w  .  j  av  a2s  .  co m
    return driver;
}

From source file:com.google.caja.plugin.WebDriverHandle.java

License:Apache License

private static RemoteWebDriver makeDriver() {
    DesiredCapabilities dc = new DesiredCapabilities();

    String browserType = TestFlag.BROWSER.getString("firefox");

    if ("chrome".equals(browserType)) {
        // Chrome driver is odd in that the path to Chrome is specified
        // by a desiredCapability when you start a session. The other
        // browser drivers will read a java system property on start.
        // This applies to both remote Chrome and local Chrome.
        ChromeOptions chromeOpts = new ChromeOptions();
        String chromeBin = TestFlag.CHROME_BINARY.getString(null);
        if (chromeBin != null) {
            chromeOpts.setBinary(chromeBin);
        }//www .  j a v  a 2 s . c o  m
        String chromeArgs = TestFlag.CHROME_ARGS.getString(null);
        if (chromeArgs != null) {
            String[] args = chromeArgs.split(";");
            chromeOpts.addArguments(args);
        }
        dc.setCapability(ChromeOptions.CAPABILITY, chromeOpts);
    }

    String url = TestFlag.WEBDRIVER_URL.getString("");

    if (!"".equals(url)) {
        dc.setBrowserName(browserType);
        dc.setJavascriptEnabled(true);
        try {
            return new RemoteWebDriver(new URL(url), dc);
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
    } else if ("chrome".equals(browserType)) {
        return new ChromeDriver(dc);
    } else if ("firefox".equals(browserType)) {
        return new FirefoxDriver();
    } else if ("safari".equals(browserType)) {
        // TODO(felix8a): local safari doesn't work yet
        return new SafariDriver();
    } else {
        throw new RuntimeException("No local driver for browser type '" + browserType + "'");
    }
}

From source file:com.hpe.nv.samples.advanced.AdvAllTestClassMethods.java

License:Apache License

public static void buildSeleniumWebDriver() {
    logDebugMessage("Building the Selenium WebDriver for " + browser);

    if (proxySetting != null) {
        Proxy proxy = new Proxy();
        proxy.setHttpProxy(proxySetting).setFtpProxy(proxySetting).setSslProxy(proxySetting)
                .setSocksProxy(proxySetting);
        DesiredCapabilities cap = new DesiredCapabilities();
        cap.setCapability(CapabilityType.PROXY, proxy);

        if (browser.equalsIgnoreCase("Firefox")) {
            driver = new FirefoxDriver(cap);
        } else {/* w  w w. j av  a 2 s  . c  om*/
            driver = new ChromeDriver(cap);
        }
    } else {
        if (browser.equalsIgnoreCase("Firefox")) {
            driver = new FirefoxDriver();
        } else {
            driver = new ChromeDriver();
        }
    }
}

From source file:com.ibm.sbt.automation.core.environment.TestEnvironment.java

License:Open Source License

private void initChromeDriver() {
    String chromeDriver = System.getProperty(PROP_WEBDRIVER_CHROMER_DRIVER);
    if (StringUtil.isEmpty(chromeDriver)) {
        String userDir = System.getProperty(PROP_USER_DIR);
        String driverPath = userDir + "/../../../tools/com.ibm.sbtx.ci/selenium/Chrome/chromedriver.exe";
        System.setProperty(PROP_WEBDRIVER_CHROMER_DRIVER, driverPath);
    }/*from  ww w .  j  a  va  2  s  .  co  m*/
    if (!StringUtil.isEmpty(System.getProperty(PROP_CHROME_BINARY))) {
        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        capabilities.setCapability("chrome.binary", System.getProperty(PROP_CHROME_BINARY));
        webDriver = new ChromeDriver(capabilities);
    } else {
        webDriver = new ChromeDriver();
    }
}

From source file:com.kurento.kmf.test.client.BrowserClient.java

License:Open Source License

private void initDriver(String hostAddress) {
    Class<? extends WebDriver> driverClass = browser.getDriverClass();
    int hubPort = getProperty("test.hub.port", GridBrowserMediaApiTest.DEFAULT_HUB_PORT);

    try {/*  www.  jav a  2  s. c  o m*/
        if (driverClass.equals(FirefoxDriver.class)) {
            FirefoxProfile profile = new FirefoxProfile();
            // This flag avoids granting the access to the camera
            profile.setPreference("media.navigator.permission.disabled", true);
            if (remoteNode != null) {
                DesiredCapabilities capabilities = new DesiredCapabilities();
                capabilities.setCapability(FirefoxDriver.PROFILE, profile);
                capabilities.setBrowserName(DesiredCapabilities.firefox().getBrowserName());

                driver = new RemoteWebDriver(new URL("http://" + hostAddress + ":" + hubPort + "/wd/hub"),
                        capabilities);
            } else {
                driver = new FirefoxDriver(profile);
            }

            if (!usePhysicalCam && video != null) {
                launchFakeCam();
            }

        } else if (driverClass.equals(ChromeDriver.class)) {
            String chromedriver = null;
            if (SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_LINUX) {
                chromedriver = "chromedriver";
            } else if (SystemUtils.IS_OS_WINDOWS) {
                chromedriver = "chromedriver.exe";
            }
            System.setProperty("webdriver.chrome.driver",
                    new File("target/webdriver/" + chromedriver).getAbsolutePath());
            ChromeOptions options = new ChromeOptions();

            // This flag avoids grant the camera
            options.addArguments("--use-fake-ui-for-media-stream");

            // This flag avoids warning in chrome. See:
            // https://code.google.com/p/chromedriver/issues/detail?id=799
            options.addArguments("--test-type");

            if (!usePhysicalCam) {
                // This flag makes using a synthetic video (green with
                // spinner) in webrtc. Or it is needed to combine with
                // use-file-for-fake-video-capture to use a file faking the
                // cam
                options.addArguments("--use-fake-device-for-media-stream");

                if (video != null) {
                    options.addArguments("--use-file-for-fake-video-capture=" + video);

                    // Alternative: lauch fake cam also in Chrome
                    // launchFakeCam();
                }
            }

            if (remoteNode != null) {
                DesiredCapabilities capabilities = new DesiredCapabilities();
                capabilities.setCapability(ChromeOptions.CAPABILITY, options);
                capabilities.setBrowserName(DesiredCapabilities.chrome().getBrowserName());
                driver = new RemoteWebDriver(new URL("http://" + hostAddress + ":" + hubPort + "/wd/hub"),
                        capabilities);

            } else {
                driver = new ChromeDriver(options);
            }

        }
        driver.manage().timeouts().setScriptTimeout(timeout, TimeUnit.SECONDS);

    } catch (MalformedURLException e) {
        log.error("MalformedURLException in BrowserClient.initDriver", e);
    }
}

From source file:com.kurento.test.selenium.BaseSeleniumTst.java

License:Open Source License

private void setup(Class<? extends WebDriver> driverClass) {
    if (driverClass.equals(FirefoxDriver.class)) {
        driver = new FirefoxDriver();

    } else if (driverClass.equals(ChromeDriver.class)) {
        String chromedriver = null;
        if (SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_LINUX) {
            chromedriver = "chromedriver";
        } else if (SystemUtils.IS_OS_WINDOWS) {
            chromedriver = "chromedriver.exe";
        }//from  w  w  w  . j  ava  2 s.c o m
        System.setProperty("webdriver.chrome.driver",
                new File("target/webdriver/" + chromedriver).getAbsolutePath());
        ChromeOptions options = new ChromeOptions();

        // This flag avoids a warning in chrome. See:
        // https://code.google.com/p/chromedriver/issues/detail?id=799
        options.addArguments("--test-type");

        driver = new ChromeDriver(options);
    }
}

From source file:com.kurento.test.selenium.MixerTst.java

License:Open Source License

private WebDriver createDriver(Class<? extends WebDriver> driverClass) {
    WebDriver driver = null;//from   ww  w .j  a va2  s . c  om
    if (driverClass.equals(FirefoxDriver.class)) {
        driver = new FirefoxDriver();

    } else if (driverClass.equals(ChromeDriver.class)) {
        String chromedriver = null;
        if (SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_LINUX) {
            chromedriver = "chromedriver";
        } else if (SystemUtils.IS_OS_WINDOWS) {
            chromedriver = "chromedriver.exe";
        }
        System.setProperty("webdriver.chrome.driver",
                new File("target/webdriver/" + chromedriver).getAbsolutePath());
        ChromeOptions options = new ChromeOptions();

        // This flag avoids a warning in chrome. See:
        // https://code.google.com/p/chromedriver/issues/detail?id=799
        options.addArguments("--test-type");

        // This flag avoids grant the camera
        options.addArguments("--use-fake-ui-for-media-stream");

        // This flag makes using a synthetic video (green with
        // spinner) in webrtc. Or it is needed to combine with
        // use-file-for-fake-video-capture to use a file faking the
        // cam
        options.addArguments("--use-fake-device-for-media-stream");

        driver = new ChromeDriver(options);
    }
    return driver;
}

From source file:com.kurento.test.selenium.WebRtcTst.java

License:Open Source License

private void setup(Class<? extends WebDriver> driverClass) {
    if (driverClass.equals(FirefoxDriver.class)) {
        driver = new FirefoxDriver();

    } else if (driverClass.equals(ChromeDriver.class)) {
        String chromedriver = null;
        if (SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_LINUX) {
            chromedriver = "chromedriver";
        } else if (SystemUtils.IS_OS_WINDOWS) {
            chromedriver = "chromedriver.exe";
        }//from  www.j  av a2s  .c  o m
        System.setProperty("webdriver.chrome.driver",
                new File("target/webdriver/" + chromedriver).getAbsolutePath());
        ChromeOptions options = new ChromeOptions();

        // This flag avoids a warning in chrome. See:
        // https://code.google.com/p/chromedriver/issues/detail?id=799
        options.addArguments("--test-type");

        // This flag avoids grant the camera
        options.addArguments("--use-fake-ui-for-media-stream");

        // This flag makes using a synthetic video (green with
        // spinner) in webrtc. Or it is needed to combine with
        // use-file-for-fake-video-capture to use a file faking the
        // cam
        options.addArguments("--use-fake-device-for-media-stream");

        driver = new ChromeDriver(options);
    }
}