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:jp.co.nssol.h5.test.selenium.base.DriverFactory.java

License:Apache License

/**
 * ChromeDriver???// w  w  w .j  a v  a  2 s  . co 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

protected DesiredCapabilities getDesiredCapabilities() {
    final DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    {/*  w w w.  ja  v a 2  s. c  o m*/
        {
            final ChromeOptions chromeOptions = new ChromeOptions();

            {
                final HashMap<String, Object> prefsMap = new HashMap<String, Object>();
                prefsMap.put("profile.default_content_settings.popups", 0);
                // prefsMap.put("download.default_directory", ???);
                chromeOptions.setExperimentalOption("prefs", prefsMap);
            }

            if (DEVICE_IPHONE.equals(deviceName)) {
                final Map<String, String> mobileEmulationMap = new HashMap<String, String>();
                mobileEmulationMap.put("deviceName", "Apple iPhone 6");
                chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulationMap);
            }

            if (userDataDir != null && userDataDir.trim().length() > 0) {
                chromeOptions.addArguments("user-data-dir=" + userDataDir);
            }

            capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
        }
    }

    {
        capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    }

    {
        final LoggingPreferences preferences = new LoggingPreferences();
        preferences.enable(LogType.BROWSER, Level.ALL);
        capabilities.setCapability(CapabilityType.LOGGING_PREFS, preferences);
    }
    return capabilities;
}

From source file:loblaw.provisioning.TicketCreator.java

private void init() {
    System.setProperty("webdriver.chrome.driver", chromeDriverPath);
    ChromeOptions opt = new ChromeOptions();
    opt.addArguments("--user-data-dir=C:/ChromeProfile");//custom profile so that logins save
    activeBrowser = new ChromeDriver(opt);
    activeBrowser.get(newTicket + ticketTemplate);
}

From source file:mooltipass.AftBase.java

License:Open Source License

@BeforeClass
public static void beforeClass() throws Exception {
    chromeDriverService = chromeDriverService();
    if (chromeDriverService != null) {
        chromeDriverService.start();/*from  www .j  ava 2 s  . co m*/
    }

    ChromeOptions options = new ChromeOptions();

    // Appears you can only load one unpacked extensions this way...
    // list doesn't do it
    //      List<String> arguments = new LinkedList<String>();
    //      arguments.add("load-extension=" + System.getProperty(MOOLTIPASS_DIR) + File.separator + "authentication_clients" + File.separator + "chrome.hid-app");
    //      arguments.add("load-extension=" + System.getProperty(MOOLTIPASS_DIR) + File.separator + "authentication_clients" + File.separator + "chrome-ext");
    //      options.addArguments(arguments);
    // comma delimited as some chrome arguments use doesn't work
    //      options.addArguments("load-extension=" + System.getProperty(MOOLTIPASS_DIR) + File.separator + "authentication_clients" + File.separator + "chrome.hid-app","load-extension=" + System.getProperty(MOOLTIPASS_DIR) + File.separator + "authentication_clients" + File.separator + "chrome-ext");
    // String... doesn't work      
    //      options.addArguments("load-extension=" + System.getProperty(MOOLTIPASS_DIR) + File.separator + "authentication_clients" + File.separator + "chrome.hid-app," + System.getProperty(MOOLTIPASS_DIR) + File.separator + "authentication_clients" + File.separator + "chrome-ext");

    // Requires extensions are crx (zip file with public and private keys)
    //      List extensions = new LinkedList();
    //      extensions.add(new File(System.getProperty(MOOLTIPASS_DIR) + File.separator + "authentication_clients" + File.separator + "chrome.hid-app"));
    //      extensions.add(new File(System.getProperty(MOOLTIPASS_DIR) + File.separator + "authentication_clients" + File.separator + "chrome-ext"));
    //      options.addExtensions(extensions);

    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);

    System.out.println("Starting an instance of chrome.");
    driver = new ChromeDriver(capabilities);

    // TODO figure out how to pre-install extensions automatically (see commented out code above for things that don't work)
    driver.get("chrome://extensions/");
    System.out.println(
            "\nWaiting " + getTimeoutExtension() / 1000 + " seconds for you to install Extensions manually.");
    System.out.println(
            "Check the Developer mode checkbox and then use the Load unpackaged extensions to load the mooltipass authentication_clients chrome.hid-app and chrome.ext\n");
    try {
        Thread.sleep(getTimeoutExtension());
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:net.codestory.simplelenium.driver.chrome.ChromeDriverDownloader.java

License:Apache License

protected ChromeOptions getChromeOptions() {
    ChromeOptions options = new ChromeOptions();

    if (isMac()) {
        // Try to use the chrome installed by homebrew cask
        File chromeInstalledByHomebrew = new File(
                "/opt/homebrew-cask/Caskroom/google-chrome/latest/Google Chrome.app/Contents/MacOS/Google Chrome");
        if (chromeInstalledByHomebrew.exists()) {
            options.setBinary(chromeInstalledByHomebrew);
        }/*from   w  w w  .  j  a va 2s . c  o  m*/
    }

    return options;
}

From source file:net.continuumsecurity.web.drivers.DriverFactory.java

License:Open Source License

public WebDriver createChromeDriver(DesiredCapabilities capabilities) {
    System.setProperty("webdriver.chrome.driver", Config.getInstance().getDefaultDriverPath());

    if (capabilities != null) {
        capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--test-type");
        capabilities.setCapability(ChromeOptions.CAPABILITY, options);
        return new ChromeDriver(capabilities);

    } else/* w w  w .  j ava2s  .com*/
        return new ChromeDriver();

}

From source file:openpath.Main.java

public void other(String[] args) throws IOException {

    String webdriverPath = "/usr/local/bin/chromedriver";
    String chromePath = "/usr/bin/google-chrome";
    String downloadDir = "/opt/tmp/openpath";

    ChromeDriverService service = new ChromeDriverService.Builder()
            .usingDriverExecutable(new File(webdriverPath)).usingAnyFreePort().build();

    Map<String, Object> prefs = new HashMap<>();
    prefs.put("download.default_directory", downloadDir);

    ChromeOptions opts = new ChromeOptions();
    opts.setBinary(new File(chromePath));
    opts.setExperimentalOption("prefs", prefs);
    DesiredCapabilities caps = DesiredCapabilities.chrome();
    caps.setCapability(ChromeOptions.CAPABILITY, opts);

    service.start();/*from  www .  j  a va 2  s .  c  o  m*/

    WebDriver drv = new RemoteWebDriver(service.getUrl(), caps);

    OpenPathDriver opDrv = new OpenPathDriver(drv, m -> {
        System.out.println(">> " + m);
    });

    String opUsername = "caiyuhao0125@hotmail.com";
    String opPassword = "19910125";

    opDrv.download(opUsername, opPassword, Paths.get(downloadDir));

    service.stop();

    System.exit(0);
}

From source file:org.alfresco.grid.WebDriverFactory.java

License:Open Source License

public WebDriver getObject(Browser browser) {
    switch (browser) {
    case FireFox:
        return getFireFox(false);
    case Chrome:/* w w  w.  j a va2s.c  o  m*/
        return getChromeDriver();
    case HtmlUnit:
        return new HtmlUnitDriver(true);
    case IE:
        return getInternetExplorerDriver();
    case Safari:
        return getSafariDriver();
    case RemoteFireFox:
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setBrowserName(BrowserType.FIREFOX);
        capabilities.setJavascriptEnabled(true);
        FirefoxProfile profile = createProfile();
        //The below two preferences added to disable the firefox auto update
        profile.setPreference("app.update.auto", false);
        profile.setPreference("app.update.enabled", false);
        profile.setEnableNativeEvents(true);
        capabilities.setCapability(FirefoxDriver.PROFILE, profile);
        return getRemoteDriver(capabilities);
    case RemoteChrome:
        DesiredCapabilities chromeCapabilities = DesiredCapabilities.chrome();
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--kiosk");
        chromeCapabilities.setCapability(ChromeOptions.CAPABILITY, options);
        return getRemoteDriver(chromeCapabilities);
    case RemoteIE:
        DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
        ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
                true);
        return getRemoteDriver(ieCapabilities);
    case FireFoxDownloadToDir:
        return getFireFox(true);
    default:
        throw new IllegalArgumentException("Invalid browser specified");
    }
}

From source file:org.alfresco.grid.WebDriverFactory.java

License:Open Source License

/**
 * Creates new instance of {@link ChromeDriver}.
 * @return {@link WebDriver} instance of {@link ChromeDriver}
 *//*from w ww  . j ava2s . c o m*/
private WebDriver getChromeDriver() {
    if (chromeServerPath == null || chromeServerPath.isEmpty()) {
        throw new RuntimeException("Failed to create ChromeDriver, require a valid chromeServerPath");
    }
    Properties props = System.getProperties();
    if (!props.containsKey(CHROME_SERVER_DRIVER_PATH)) {
        props.put(CHROME_SERVER_DRIVER_PATH, chromeServerPath);
    }
    ChromeOptions options = new ChromeOptions();
    //Chrome Option to add full Screen Mode.
    options.addArguments("--kiosk");
    return new ChromeDriver(options);
}

From source file:org.aludratest.service.gui.web.selenium.selenium2.DefaultSeleniumWebDriverFactory.java

License:Apache License

private static DesiredCapabilities createChromeCaps() {
    DesiredCapabilities caps = DesiredCapabilities.chrome();
    ChromeOptions opts = new ChromeOptions();
    caps.setCapability(ChromeOptions.CAPABILITY, opts);
    return caps;//ww  w  .  j a v a  2s  .co m
}