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:io.github.bonigarcia.wdm.test.WebRtcChromeTest.java

License:Apache License

@Before
public void setupTest() {
    ChromeOptions options = new ChromeOptions();

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

    // This flag fakes user media with synthetic video (green with spinner
    // and timer)
    options.addArguments("--use-fake-device-for-media-stream");

    driver = new ChromeDriver(options);
}

From source file:io.github.mike10004.vhs.testsupport.MakeFileUploadHar.java

License:Open Source License

private static WebDriver createWebDriver(int proxyPort) {
    ChromeOptions options = new ChromeOptions();
    options.addArguments("--proxy-server=localhost:" + proxyPort);
    ChromeDriverSetupRule.doSetup();/*from   w ww .java  2  s . co  m*/
    WebDriver driver = new ChromeDriver(options);
    return driver;
}

From source file:io.github.seleniumquery.browser.driver.builders.ChromeDriverBuilder.java

License:Apache License

private WebDriver buildChrome() {
    configureChromeServerExecutablePath();
    try {//from  w  ww . java 2s .com
        return new ChromeDriver(getInitializedChromeOptions());
    } catch (IllegalStateException e) {
        throwCustomExceptionIfExecutableWasNotFound(e);
        throw e;
    }
}

From source file:io.openvidu.test.browsers.ChromeAndroidUser.java

License:Apache License

public ChromeAndroidUser(String userName, int timeOfWaitInSeconds) {
    super(userName, timeOfWaitInSeconds);

    Map<String, String> mobileEmulation = new HashMap<>();
    mobileEmulation.put("deviceName", "Pixel 2");

    ChromeOptions chromeOptions = new ChromeOptions();
    chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation);

    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setAcceptInsecureCerts(true);
    capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);

    // This flag avoids to grant the user media
    chromeOptions.addArguments("--use-fake-ui-for-media-stream");
    // This flag fakes user media with synthetic video
    chromeOptions.addArguments("--use-fake-device-for-media-stream");

    String REMOTE_URL = System.getProperty("REMOTE_URL_CHROME");
    if (REMOTE_URL != null) {
        log.info("Using URL {} to connect to remote web driver", REMOTE_URL);
        try {// w  ww  . j av a2  s  .co m
            this.driver = new RemoteWebDriver(new URL(REMOTE_URL), capabilities);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    } else {
        log.info("Using local web driver");
        this.driver = new ChromeDriver(capabilities);
    }

    this.driver.manage().timeouts().setScriptTimeout(this.timeOfWaitInSeconds, TimeUnit.SECONDS);
    this.configureDriver();
}

From source file:io.openvidu.test.browsers.ChromeUser.java

License:Apache License

private ChromeUser(String userName, int timeOfWaitInSeconds, ChromeOptions options) {
    super(userName, timeOfWaitInSeconds);
    options.setAcceptInsecureCerts(true);
    options.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.IGNORE);

    options.addArguments("--disable-infobars");

    Map<String, Object> prefs = new HashMap<String, Object>();
    prefs.put("profile.default_content_setting_values.media_stream_mic", 1);
    prefs.put("profile.default_content_setting_values.media_stream_camera", 1);
    options.setExperimentalOption("prefs", prefs);

    String REMOTE_URL = System.getProperty("REMOTE_URL_CHROME");
    if (REMOTE_URL != null) {
        log.info("Using URL {} to connect to remote web driver", REMOTE_URL);
        try {// w  ww .ja v  a 2 s  .  c  o m
            this.driver = new RemoteWebDriver(new URL(REMOTE_URL), options);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    } else {
        log.info("Using local web driver");
        this.driver = new ChromeDriver(options);
    }

    this.driver.manage().timeouts().setScriptTimeout(this.timeOfWaitInSeconds, TimeUnit.SECONDS);
    this.configureDriver();
}

From source file:io.wcm.qa.galenium.webdriver.WebDriverManager.java

License:Apache License

private WebDriver newDriver(TestDevice newTestDevice) {

    logInfo("Creating new " + runMode + " " + newTestDevice.getBrowserType() + " WebDriver for thread "
            + Thread.currentThread().getName());

    DesiredCapabilities capabilities = getDesiredCapabilities(newTestDevice);

    GaleniumReportUtil.getLogger().info("Getting driver for runmode '" + runMode + "'");
    switch (runMode) {
    case REMOTE://from w  ww .j  a  va  2 s.c  o m
        logInfo("Connecting to grid at " + host + ":" + port + "...");
        try {
            driver = new RemoteWebDriver(new URL("http", host, port, "/wd/hub"), capabilities);
        } catch (MalformedURLException ex) {
            throw new RuntimeException(
                    "Couldn't construct valid URL using selenium.host=" + host + " and selenium.port=" + port);
        }
        break;

    default:
    case LOCAL:
        switch (newTestDevice.getBrowserType()) {
        case CHROME:
            driver = new ChromeDriver(capabilities);
            break;

        case IE:
            driver = new InternetExplorerDriver(capabilities);
            break;

        case SAFARI:
            driver = new SafariDriver(capabilities);
            break;

        case PHANTOMJS:
            driver = new PhantomJSDriver(capabilities);
            break;

        default:
        case FIREFOX:
            driver = new FirefoxDriver(capabilities);
            break;
        }
        break;
    }

    return driver;
}

From source file:javax.portlet.tck.driver.TCKSimpleTestDriver.java

License:Apache License

/**
 * @throws java.lang.Exception//from  w  w w . ja va 2  s.  c  om
 */
@BeforeClass
public static void setUpBeforeClass() throws Exception {

    loginUrl = System.getProperty("test.server.login.url");
    host = System.getProperty("test.server.host");
    port = System.getProperty("test.server.port");
    username = System.getProperty("test.server.username");
    usernameId = System.getProperty("test.server.username.id");
    password = System.getProperty("test.server.password");
    passwordId = System.getProperty("test.server.password.id");
    browser = System.getProperty("test.browser");
    testContextBase = System.getProperty("test.context.base");
    String str = System.getProperty("test.url.strategy");
    useGeneratedUrl = str.equalsIgnoreCase("generateURLs");
    str = System.getProperty("test.debug");
    debug = str.equalsIgnoreCase("true");
    str = System.getProperty("test.timeout");
    dryrun = new Boolean(System.getProperty("test.dryrun"));
    timeout = ((str != null) && str.matches("\\d+")) ? Integer.parseInt(str) : 3;
    String wd = System.getProperty("test.browser.webDriver");
    String binary = System.getProperty("test.browser.binary");
    boolean browserDefaultHeadless = browser.equalsIgnoreCase("chrome") || browser.equalsIgnoreCase("firefox")
            || browser.equalsIgnoreCase("htmlunit") || browser.equalsIgnoreCase("phantomjs");
    String headlessProperty = System.getProperty("test.browser.headless");
    boolean headless = (((headlessProperty == null) || (headlessProperty.length() == 0))
            && browserDefaultHeadless);

    System.out.println("before class.");
    System.out.println("   Debug        =" + debug);
    System.out.println("   Dryrun       =" + dryrun);
    System.out.println("   Timeout      =" + timeout);
    System.out.println("   Login URL    =" + loginUrl);
    System.out.println("   Host         =" + host);
    System.out.println("   Port         =" + port);
    System.out.println("   Context      =" + testContextBase);
    System.out.println("   Generate URL =" + useGeneratedUrl);
    System.out.println("   Username     =" + username);
    System.out.println("   UsernameId   =" + usernameId);
    System.out.println("   Password     =" + password);
    System.out.println("   PasswordId   =" + passwordId);
    System.out.println("   Browser      =" + browser);
    System.out.println("   Driver       =" + wd);
    System.out.println("   binary       =" + binary);
    System.out.println("   headless     =" + headless);

    if (browser.equalsIgnoreCase("firefox")) {

        System.setProperty("webdriver.gecko.driver", wd);
        FirefoxOptions options = new FirefoxOptions();
        options.setLegacy(true);
        options.setAcceptInsecureCerts(true);

        if ((binary != null) && (binary.length() != 0)) {
            options.setBinary(binary);
        }

        if (headless) {
            options.setHeadless(true);
        }

        driver = new FirefoxDriver(options);

    } else if (browser.equalsIgnoreCase("internetExplorer")) {
        System.setProperty("webdriver.ie.driver", wd);
        driver = new InternetExplorerDriver();
    } else if (browser.equalsIgnoreCase("chrome")) {

        System.setProperty("webdriver.chrome.driver", wd);
        ChromeOptions options = new ChromeOptions();

        if ((binary != null) && (binary.length() > 0)) {
            options.setBinary(binary);
        }

        if (headless) {
            options.addArguments("--headless");
        }

        options.addArguments("--disable-infobars");
        options.setAcceptInsecureCerts(true);

        driver = new ChromeDriver(options);

    } else if (browser.equalsIgnoreCase("phantomjs")) {
        DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
        capabilities.setJavascriptEnabled(true);
        capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, binary);
        driver = new PhantomJSDriver(capabilities);
    } else if (browser.equalsIgnoreCase("htmlUnit")) {
        driver = new HtmlUnitDriver(true);
    } else if (browser.equalsIgnoreCase("safari")) {
        driver = new SafariDriver();
    } else {
        throw new Exception("Unsupported browser: " + browser);
    }

    if (!dryrun) {
        login();
    }

}

From source file:jp.co.nssol.h5.test.selenium.base.DriverFactory.java

License:Apache License

/**
 * ChromeDriver???/*from www  . java  2s .  c o  m*/
 *
 * @return ChromeDriver
 */
private static WebDriver setupChromeDriver() {
    System.setProperty("webdriver.chrome.driver", SettingsReader.getProperty(PKEY_CHROMIUM_PATH));
    ChromeOptions options = new ChromeOptions();
    options.addArguments("--ignore-certificate-errors");
    return new ChromeDriver(options) {
        @Override
        public String toString() {
            return "Chrome";
        }
    };
}

From source file:jp.igapyon.selecrawler.util.SimpleChromeWrapper.java

License:Open Source License

public void open() {
    final DesiredCapabilities capabilities = getDesiredCapabilities();

    driver = new ChromeDriver(capabilities);

    driver.manage().timeouts().implicitlyWait(WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    driver.manage().timeouts().pageLoadTimeout(WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
}

From source file:jscover.server.WebDriverChromeTest.java

License:Open Source License

@Override
public WebDriver getWebClient() {
    return new ChromeDriver(new DesiredCapabilities());
}