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:com.comcast.dawg.selenium.BrowserServiceManager.java

License:Apache License

/**
 * Provides the browser desired capabilities.
 *
 * @param browser/*from  www  .j  av  a  2s .  c om*/
 *        Browser for which the desired capabilities to be returned.
 * @return Capabilities corresponding to the browser passed.
 */
private static Capabilities getDesiredBrowserCapabilities(Browser browser) {
    DesiredCapabilities capabilities = null;
    switch (browser) {
    case chrome:
        ChromeOptions options = new ChromeOptions();
        options.addArguments(CHROME_OPTION_ARGUMENTS);
        capabilities = DesiredCapabilities.chrome();
        capabilities.setCapability(ChromeOptions.CAPABILITY, options);
        break;
    default:
        capabilities = new DesiredCapabilities();
        break;
    }
    return capabilities;
}

From source file:com.daarons.transfer.DownloadTask.java

License:Apache License

private void initChromeDriver() {
    System.setProperty("webdriver.chrome.driver", "chromedriver_win32/chromedriver.exe");
    ChromeOptions options = new ChromeOptions();
    options.addArguments("--start-maximized");
    driver = new ChromeDriver(options);
}

From source file:com.elastica.browserfactory.ChromeCapabilitiesFactory.java

License:Apache License

public DesiredCapabilities createCapabilities(final DriverConfig webDriverConfig) {

    DesiredCapabilities capability = null;
    capability = DesiredCapabilities.chrome();
    capability.setBrowserName(DesiredCapabilities.chrome().getBrowserName());

    ChromeOptions options = new ChromeOptions();
    if (webDriverConfig.getUserAgentOverride() != null) {
        options.addArguments("--user-agent=" + webDriverConfig.getUserAgentOverride());
    }/*from w  w w. jav a2  s.  c o m*/

    capability.setCapability(ChromeOptions.CAPABILITY, options);

    if (webDriverConfig.isEnableJavascript()) {
        capability.setJavascriptEnabled(true);
    } else {
        capability.setJavascriptEnabled(false);
    }

    capability.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
    capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

    if (webDriverConfig.getBrowserVersion() != null) {
        capability.setVersion(webDriverConfig.getBrowserVersion());
    }

    if (webDriverConfig.getPlatform() != null) {
        capability.setPlatform(webDriverConfig.getPlatform());
    }

    if (webDriverConfig.getProxyHost() != null) {
        Proxy proxy = webDriverConfig.getProxy();
        capability.setCapability(CapabilityType.PROXY, proxy);
    }

    if (webDriverConfig.getChromeBinPath() != null) {
        capability.setCapability("chrome.binary", webDriverConfig.getChromeBinPath());
    }

    // Set ChromeDriver for local mode
    if (webDriverConfig.getMode() == DriverMode.LOCAL) {
        String chromeDriverPath = webDriverConfig.getChromeDriverPath();
        if (chromeDriverPath == null) {
            try {
                if (System.getenv("webdriver.chrome.driver") != null) {
                    System.out.println(
                            "get Chrome driver from property:" + System.getenv("webdriver.chrome.driver"));
                    System.setProperty("webdriver.chrome.driver", System.getenv("webdriver.chrome.driver"));
                } else {
                    handleExtractResources();
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        } else {
            System.setProperty("webdriver.chrome.driver", chromeDriverPath);
        }
    }

    return capability;
}

From source file:com.epam.jdi.uitests.web.selenium.driver.SeleniumDriverFactory.java

License:Open Source License

private ChromeOptions defaultChromeOptions() {
    ChromeOptions cap = new ChromeOptions();
    cap.setCapability(PAGE_LOAD_STRATEGY, pageLoadStrategy);
    return cap;
}

From source file:com.formkiq.web.SeleniumTestBase.java

License:Apache License

/**
 * Create Chrome Driver.//ww w .  j av a  2  s  . com
 */
protected static void initializeChromeDriver() {

    String path = "src/test/resources/selenium/chromedriver";

    if (SystemUtils.IS_OS_WINDOWS) {
        path += ".exe";
    }

    System.setProperty("webdriver.chrome.driver", path);

    ChromeOptions options = new ChromeOptions();
    options.setHeadless(true);
    driver = new ChromeDriver(options);
    isInitialized = true;
}

From source file:com.fullteaching.backend.e2e.ChromeUser.java

License:Apache License

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

    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
    options.addArguments("--use-fake-device-for-media-stream");
    // This flag selects the entire screen as video source when screen sharing
    options.addArguments("--auto-select-desktop-capture-source=Entire screen");

    String eusApiURL = System.getenv("ET_EUS_API");

    if (eusApiURL == null) {
        this.driver = new ChromeDriver(options);
    } else {/*from  w w  w.  j a v  a  2  s  .  c  o m*/

        try {
            DesiredCapabilities caps = new DesiredCapabilities();
            caps.setBrowserName("chrome");
            //caps.setVersion("61");
            caps.setCapability(ChromeOptions.CAPABILITY, options);

            this.driver = new RemoteWebDriver(new URL(eusApiURL), caps);

        } catch (MalformedURLException e) {
            throw new RuntimeException("Exception creaing eusApiURL", e);
        }
    }

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

    this.configureDriver();
}

From source file:com.galois.fiveui.drivers.Drivers.java

License:Apache License

public static ChromeDriver buildChromeDriver() {

    String rootPath = getRootPath();

    // set the chrome driver path:
    String chromeDriverPth = mkPath(CD_BASE_PATH, osNameArch(), CD_BINARY_NAME);
    System.setProperty("webdriver.chrome.driver", chromeDriverPth);

    // setting the path to chrome also seems to cause issues:
    ChromeOptions options = new ChromeOptions();
    options.addArguments("--user-data-dir=" + rootPath + chromeProfilePath); // ,
    // "--enable-logging",
    // "--v=1");/*from w  w w . ja v a2s.  c om*/

    String chromeBinaryPath = System.getProperty(CHROME_BIN_PATH);
    if (null == chromeBinaryPath) {
        System.err.println("WARNING: Running essentially random version of Chrome!");
        System.err.println("         set a path to Chrome with -D" + CHROME_BIN_PATH + "=<path to chrome>");
    } else {
        options.setBinary(new File(chromeBinaryPath));
    }
    // For use with ChromeDriver:
    return new ChromeDriver(options);
}

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

License:Open Source License

/**
 * initialization ChromeDriver//  w  ww.j  av  a 2s. co 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);
    }//  w  w  w.j  a va  2 s . c om
    return driver;
}

From source file:com.github.mike10004.seleniumhelp.UnitTests.java

License:Apache License

/**
 * Creates a Chrome options object suitable for unit tests. Some build environments
 * (I'm looking at you, Travis) require some tweaks to the way Chrome is executed,
 * and this allows you to specify those tweaks with a system property. The value
 * of the property is tokenized on breaking whitespace, so there's no way to include
 * an actual space within an argument, but the need for that completeness is uncommon
 * enough that we'll ignore it for now. This also sets the Chrome executable from
 * system property {@link #SYSPROP_CHROME_EXECUTABLE_PATH} or environment variable
 * {@link #ENV_CHROME_BIN}.//from ww  w  .  ja  va 2  s. c o  m
 * @return an options object with parameters set
 */
public static ChromeOptions createChromeOptions() {
    ChromeOptions options = new ChromeOptions();
    String executablePath = getChromeExecutablePath();
    if (executablePath != null) {
        options.setBinary(executablePath);
    }
    options.addArguments(getChromeOptionsExtraArgs());
    return options;
}