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

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

Introduction

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

Prototype

public ChromeOptions() 

Source Link

Usage

From source file:de.learnlib.alex.learning.entities.webdrivers.ChromeDriverConfig.java

License:Apache License

@Override
public WebDriver createDriver() throws Exception {
    final ChromeOptions chromeOptions = new ChromeOptions();
    if (headless) {
        chromeOptions.setHeadless(true);
    }/*from  w ww .  ja  v  a 2 s .c o m*/

    final Map<String, String> environmentVariables = new HashMap<>();
    final ChromeDriverService service = new ChromeDriverService.Builder().usingAnyFreePort()
            .withEnvironment(environmentVariables).build();

    final WebDriver driver = new ChromeDriver(service, chromeOptions);
    manage(driver);

    return driver;
}

From source file:de.learnlib.alex.learning.entities.webdrivers.RemoteDriverConfig.java

License:Apache License

@Override
public WebDriver createDriver() throws Exception {
    final URL remoteURL = new URL(System.getProperty("webdriver.remote.url"));

    final DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setPlatform(platform);/*from  ww w. j av  a2 s.c  o m*/
    capabilities.setBrowserName(browser);

    switch (browser) {
    case "chrome":
        final ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.setHeadless(headless);
        capabilities.merge(chromeOptions);
        break;
    case "firefox":
        final FirefoxOptions firefoxOptions = new FirefoxOptions();
        firefoxOptions.setHeadless(headless);
        capabilities.merge(firefoxOptions);
        break;
    default:
        break;
    }

    if (!version.trim().equals("")) {
        capabilities.setVersion(version);
    }

    final WebDriver driver = new RemoteWebDriver(remoteURL, capabilities);
    manage(driver);
    return driver;
}

From source file:de.ppi.selenium.browser.DefaultWebDriverFactory.java

License:Apache License

@Override
public WebDriver createWebDriver(Map<String, String> options, DesiredCapabilities capabilities)
        throws IOException {
    ClientProperties properties = new ClientProperties(options.get(CLIENT_PROPERTIES_KEY));

    WebDriver wd = null;/*from w  ww.j a  v a  2  s . c o m*/
    DesiredCapabilities desiredCapabilities = new DesiredCapabilities(capabilities);
    String browser = properties.getBrowser();

    if (properties.isUseGrid()) {
        RemoteWebDriver remoteWebDriver = new RemoteWebDriver(new URL(properties.getGridUrl()), capabilities);
        remoteWebDriver.setFileDetector(new LocalFileDetector());
        wd = remoteWebDriver;
    } else {
        if (browser == null || browser.equals("")) {
            throw new RuntimeException(
                    "Browser cannot be null. Please set 'browser' in client properties. Supported browser types: IE, Firefox, Chrome, Safari, HtmlUnit.");
        } else if (browser.equalsIgnoreCase("ie") || browser.equalsIgnoreCase("iexplore")
                || browser.equalsIgnoreCase("*iexplore")) {
            String webdriverIEDriver = properties.getWebDriverIEDriver();

            if (webdriverIEDriver != null) {
                System.setProperty("webdriver.ie.driver", webdriverIEDriver);
            }

            String browserVersion = properties.getBrowserVersion();

            if (browserVersion == null || browserVersion.equals("")) {
                throw new RuntimeException(
                        "When using IE as the browser, please set 'browser.version' in client properties");
            } else {
                if (browserVersion.startsWith("9")) {
                    desiredCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
                    desiredCapabilities.setCapability(
                            InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
                    wd = new InternetExplorerDriver(desiredCapabilities);
                } else {
                    wd = new InternetExplorerDriver(desiredCapabilities);
                }
            }
        } else if ((browser.equalsIgnoreCase("firefox") || browser.equalsIgnoreCase("*firefox"))) {
            final String ffProfileFolder = properties.getFirefoxProfileFolder();
            final String ffProfileFile = properties.getFirefoxProfileFile();
            final String path = properties.getFfBinaryPath();
            final FirefoxProfile ffp;
            if (ffProfileFolder != null) {
                ffp = new FirefoxProfile(new File(ffProfileFolder));
            } else {
                ffp = new FirefoxProfile();
            }

            if (ffProfileFile != null) {
                addPreferences(ffp, ffProfileFile);
            }

            addPreferences(ffp, properties);

            List<String> ffExtensions = properties.getFirefoxExtensions();
            if (ffExtensions != null && ffExtensions.size() > 0) {
                addExtensionsToFirefoxProfile(ffp, ffExtensions);
            }

            if (path != null) {
                FirefoxBinary fireFox = getFFBinary(path);
                wd = new FirefoxDriver(fireFox, ffp, desiredCapabilities);
            } else {
                wd = new FirefoxDriver(new FirefoxBinary(), ffp, desiredCapabilities);

            }
        } else if (browser.equalsIgnoreCase("chrome")) {

            final String webdriverChromeDriver = properties.getWebDriverChromeDriver();

            if (webdriverChromeDriver != null) {
                System.setProperty("webdriver.chrome.driver", webdriverChromeDriver);
            }

            final ChromeOptions chromeOptions = new ChromeOptions();
            final String chromeBinaryPath = properties.getChromeBinaryPath();
            if (chromeBinaryPath != null) {
                chromeOptions.setBinary(chromeBinaryPath);
            }

            if (properties.getAcceptedLanguages() != null) {

                final Map<String, Object> prefs = new HashMap<String, Object>();
                prefs.put("intl.accept_languages", properties.getAcceptedLanguages());
                chromeOptions.setExperimentalOption("prefs", prefs);
            }
            desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);

            wd = new ChromeDriver(desiredCapabilities);

        } else if (browser.equalsIgnoreCase("safari")) {
            wd = new SafariDriver(desiredCapabilities);
        } else if (browser.equalsIgnoreCase("htmlunit")) {
            final BrowserVersion browserVersion = BrowserVersion.FIREFOX_45;
            if (properties.getAcceptedLanguages() != null) {
                browserVersion.setBrowserLanguage(properties.getAcceptedLanguages().split(",")[0]);
            }
            wd = new HtmlUnitDriver(browserVersion);
            ((HtmlUnitDriver) wd).setJavascriptEnabled(true);
        } else if (browser.equalsIgnoreCase("phantomjs")) {
            final String webdriverPhantomJSDriver = properties.getWebDriverPhantomJSDriver();
            if (properties.getAcceptedLanguages() != null) {
                desiredCapabilities.setCapability("phantomjs.page.customHeaders.Accept-Language",
                        properties.getAcceptedLanguages());
            }

            if (webdriverPhantomJSDriver != null) {
                desiredCapabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
                        webdriverPhantomJSDriver);
                wd = new PhantomJSDriver(desiredCapabilities);
            } else {
                wd = new PhantomJSDriver(ResolvingPhantomJSDriverService.createDefaultService(),
                        desiredCapabilities);
            }
        } else {
            throw new IllegalArgumentException("Unsupported browser type: " + browser
                    + ". Supported browser types: IE, Firefox, Chrome, Safari, HtmlUnit, phantomjs.");
        }

        // move browser windows to specific position. It's useful for
        // debugging...
        final int browserInitPositionX = properties.getBrowserInitPositionX();
        final int browserInitPositionY = properties.getBrowserInitPositionY();
        if (browserInitPositionX != 0 || browserInitPositionY != 0) {
            wd.manage().window().setSize(new Dimension(1280, 1024));
            wd.manage().window().setPosition(new Point(browserInitPositionX, browserInitPositionY));
        }
        wd.manage().timeouts().implicitlyWait(properties.getAppearWaitTime(), TimeUnit.MILLISECONDS);
    }

    return wd;
}

From source file:endtoend.browser.driver.builders.ChromeDriverBuilderTest.java

License:Apache License

private ChromeOptions createChromeOptionsWithMobileEmulation() {
    Map<String, String> mobileEmulation = new HashMap<>();
    mobileEmulation.put("deviceName", CHROME_MOBILE_EMULATION_DEVICE);

    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption("mobileEmulation", mobileEmulation);
    return options;
}

From source file:facebookfriendsoffriends.FacebookFriendsOfFriends.java

/**
 * @param args the command line arguments
 *//*  www. j  a v  a 2  s  . co  m*/
public FacebookFriendsOfFriends(String userName, String password) {
    this.userName = userName;
    this.password = password;
    this.facebookUrl = "https://www.facebook.com";

    this.options = new ChromeOptions();
    options.addArguments("--start-maximized");
    options.addArguments("--disable-web-security");
    options.addArguments("--no-proxy-server");
    Map<String, Object> prefs = new HashMap<String, Object>();
    prefs.put("credentials_enable_service", false);
    prefs.put("profile.password_manager_enabled", false);
    options.setExperimentalOption("prefs", prefs);
    options.addExtensions(new File(
            "/home/cbrom/.config/google-chrome/Default/Extensions/mjnbclmflcpookeapghfhapeffmpodij/1.3.0_0.crx"));
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);
    this.driver = new ChromeDriver(capabilities);
}

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

License:Apache License

@Test
public void withOptions() {
    // given//from   www. j av  a2  s .c o  m
    ChromeOptions options = new ChromeOptions();
    options.addArguments("start-maximized");
    // when
    $.driver().useChrome().withOptions(options);
    // then
    $.url(classNameToTestFileUrl(ChromeDriverBuilderTest.class));
    assertThat($("#isMaximized").text(), is("yes"));
}

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

License:Apache License

@Test
public void withCapabilities() {
    // given/*from w  w  w .  j a  v a  2 s.c o m*/
    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    ChromeOptions options = new ChromeOptions();
    options.addArguments("start-maximized");
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);
    // when
    $.driver().useChrome().withCapabilities(capabilities);
    // then
    $.url(classNameToTestFileUrl(ChromeDriverBuilderTest.class));
    assertThat($("#isMaximized").text(), is("yes"));
}

From source file:Interfaz.JFPrincipal.java

/**
 * Creates new form JFPrincipal/*  w w  w  .  j  a va2 s .co m*/
 */
public JFPrincipal() {

    // Optional, if not specified, WebDriver will search your path for chromedriver.
    System.setProperty("webdriver.chrome.driver", "C:\\SeleniumDrivers\\chromedriver.exe");

    //Hacemos la ventana de chrome grande
    ChromeOptions options = new ChromeOptions();
    options.addArguments("--start-maximized");

    driverFull = new ChromeDriver(options);
    initComponents();
    this.setIconImage(new ImageIcon(getClass().getResource("/img/ikariam.png")).getImage());
    JPLogin jpLogin = new JPLogin();
    this.setBounds(100, 500, 700, 370);
    this.getContentPane().add(jpLogin);
}

From source file:io.atlasmap.standalone.E2ETest.java

License:Apache License

@Before
public void before() {
    String driverPath = System.getProperty("webdriver.chrome.driver");
    assumeTrue(driverPath != null && !driverPath.isEmpty());

    ChromeOptions options = new ChromeOptions();
    options.addArguments("--headless", "--disable-gpu", "--no-sandbox", "--disable-setuid-sandbox");
    driver = new ChromeDriver(options);
}

From source file:io.github.bonigarcia.wdm.test.ChromeHeadlessTest.java

License:Apache License

@Before
public void setupTest() {
    ChromeOptions options = new ChromeOptions();
    // Tested in Google Chrome 59 on Linux. More info on:
    // https://developers.google.com/web/updates/2017/04/headless-chrome
    options.addArguments("--headless");
    options.addArguments("--disable-gpu");
    driver = new ChromeDriver(options);
}