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:org.aludratest.service.gui.web.selenium.selenium2.Selenium2Driver.java

License:Apache License

private static DesiredCapabilities createChromeCaps() {
    DesiredCapabilities caps = DesiredCapabilities.chrome();
    ChromeOptions opts = new ChromeOptions();
    opts.addArguments("--disable-extensions");
    caps.setCapability(ChromeOptions.CAPABILITY, opts);
    return caps;// w w w.  j  av  a  2s .  c  om
}

From source file:org.apache.activemq.transport.ws.WSTransportTest.java

License:Apache License

protected WebDriver createChromeWebDriver() throws Exception {
    File profile = new File(profileDir, "chrome");
    profile.mkdirs();//w  w w. j a va  2s .co m
    ChromeOptions options = new ChromeOptions();
    options.addArguments("--enable-udd-profiles", "--user-data-dir=" + profile,
            "--allow-file-access-from-files");
    return new ChromeDriver(options);
}

From source file:org.apache.archiva.web.test.tools.WebdriverUtility.java

License:Apache License

public static WebDriver newWebDriver(String seleniumBrowser, String seleniumHost, int seleniumPort,
        boolean seleniumRemote) {
    log.info("WebDriver {}, {}, {}, {}", seleniumBrowser, seleniumHost, seleniumPort, seleniumRemote);
    if (seleniumRemote && StringUtils.isEmpty(seleniumHost)) {
        throw new IllegalArgumentException("seleniumHost must be set, when seleniumRemote=true");
    }//  w ww .j  a  v  a 2  s  . c om
    try {

        if (StringUtils.contains(seleniumBrowser, "chrome")) {
            ChromeOptions options = new ChromeOptions();
            options.addArguments("start-maximized");
            if (seleniumRemote) {
                DesiredCapabilities capabilities = DesiredCapabilities.chrome();
                capabilities.setCapability(ChromeOptions.CAPABILITY, options);
                return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"),
                        capabilities);
            } else {
                return new ChromeDriver(options);
            }
        }

        if (StringUtils.contains(seleniumBrowser, "safari")) {
            if (seleniumRemote) {
                return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"),
                        DesiredCapabilities.safari());
            } else {
                return new SafariDriver();
            }
        }

        if (StringUtils.contains(seleniumBrowser, "iexplore")) {
            if (seleniumRemote) {
                return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"),
                        DesiredCapabilities.internetExplorer());
            } else {
                new InternetExplorerDriver();
            }
        }

        if (StringUtils.contains(seleniumBrowser, "firefox")) {
            if (seleniumRemote) {
                return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"),
                        DesiredCapabilities.firefox());
            } else {
                return new FirefoxDriver();
            }
        }

        DesiredCapabilities capabilities = DesiredCapabilities.htmlUnit();
        capabilities.setJavascriptEnabled(true);
        capabilities.setVersion("firefox-52");
        WebDriver driver;
        if (seleniumRemote) {
            driver = new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"),
                    capabilities);
        } else {
            driver = new HtmlUnitDriver(capabilities) {
                @Override
                protected WebClient modifyWebClient(WebClient client) {
                    client.getOptions().setThrowExceptionOnFailingStatusCode(false);
                    client.getOptions().setThrowExceptionOnScriptError(false);
                    client.getOptions().setCssEnabled(true);
                    return client;
                }
            };

        }
        return driver;

    } catch (MalformedURLException e) {
        throw new RuntimeException("Initializion of remote driver failed");
    }

}

From source file:org.apache.atlas.objectwrapper.WebDriverWrapper.java

License:Apache License

private static WebDriver appConfig(XmlTest config) {
    //      AtlasConstants.UI_URL = config.getParameter("app_url");
    String serverIP = config.getParameter("server_ip");
    String serverPort = config.getParameter("server_port");
    String browserName = config.getParameter("browserName");
    int browserHeight = Integer.parseInt(config.getParameter("browser_window_height"));
    int browserWidth = Integer.parseInt(config.getParameter("browser_window_width"));
    DesiredCapabilities capabilities = null;

    if (browserName.contains("firefox")) {
        capabilities = DesiredCapabilities.firefox();
        capabilities.setPlatform(Platform.ANY);
        webDriver = new FirefoxDriver(capabilities);
    } else if (browserName.contains("chrome") || browserName.equalsIgnoreCase("chrome")) {

        LOGGER.info("Configuring settings for Chrome");
        // Google Chrome Driver
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--disable-web-security");
        options.addArguments("--start-maximized");

        // For use with RemoteWebDriver:
        capabilities = DesiredCapabilities.chrome();
        capabilities.setCapability(ChromeOptions.CAPABILITY, options);
        webDriver = new ChromeDriver(capabilities);
    }/*  ww w .  j ava2s .  com*/
    AtlasConstants.UI_URL = "http://" + serverIP + ":" + serverPort;
    webDriver.manage().window().setPosition(new Point(0, 0));
    Dimension dimenssion = new Dimension(browserHeight, browserWidth);
    webDriver.manage().window().setSize(dimenssion);
    return webDriver;
}

From source file:org.apache.nutch.protocol.selenium.HttpWebClient.java

License:Apache License

public static WebDriver createChromeWebDriver(String chromeDriverPath, boolean enableHeadlessMode) {
    // if not specified, WebDriver will search your path for chromedriver
    System.setProperty("webdriver.chrome.driver", chromeDriverPath);
    ChromeOptions chromeOptions = new ChromeOptions();
    chromeOptions.addArguments("--no-sandbox");
    chromeOptions.addArguments("--disable-extensions");
    // be sure to set selenium.enable.headless to true if no monitor attached
    // to your server
    if (enableHeadlessMode) {
        chromeOptions.addArguments("--headless");
    }/* www  .ja v a  2  s  .c  om*/
    WebDriver driver = new ChromeDriver(chromeOptions);
    return driver;
}

From source file:org.apache.nutch.protocol.selenium.HttpWebClient.java

License:Apache License

public static RemoteWebDriver createChromeRemoteWebDriver(URL seleniumHubUrl, boolean enableHeadlessMode) {
    ChromeOptions chromeOptions = new ChromeOptions();
    if (enableHeadlessMode) {
        chromeOptions.setHeadless(true);
    }/*from w w  w . j a  v a 2  s. co  m*/
    RemoteWebDriver driver = new RemoteWebDriver(seleniumHubUrl, chromeOptions);
    return driver;
}

From source file:org.apache.portals.pluto.test.utilities.SimpleTestDriver.java

License:Apache License

/**
 * @throws java.lang.Exception//  ww  w  .  j  a v a  2  s .  c o  m
 */
@BeforeClass
public static void setUpBeforeClass() throws Exception {

    if (driver == null) {
        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");
        StringBuilder sb = new StringBuilder();
        sb.append("http://");
        sb.append(host);
        if (port != null && !port.isEmpty()) {
            sb.append(":");
            sb.append(port);
        }
        sb.append("/");
        sb.append(testContextBase);
        baseUrl = sb.toString();
        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 = Boolean.valueOf(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");
        String headlessProperty = System.getProperty("test.browser.headless");
        boolean headless = (((headlessProperty == null) || (headlessProperty.length() == 0)
                || Boolean.valueOf(headlessProperty)));
        String maximizedProperty = System.getProperty("test.browser.maximized");
        boolean maximized = Boolean.valueOf(maximizedProperty);

        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);
        System.out.println("   maximized    =" + maximized);

        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);

            if (maximized) {
                // The webDriver.manage().window().maximize() feature does not work correctly in headless mode, so set the
                // window size to 1920x1200 (resolution of a 15.4 inch screen).
                options.addArguments("--window-size=1920,1200");
            }

            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")) {
            LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log",
                    "org.apache.commons.logging.impl.NoOpLog");
            Logger.getLogger("com.gargoylesoftware").setLevel(Level.SEVERE);
            Logger.getLogger("org.apache.commons.httpclient").setLevel(Level.SEVERE);
            driver = new HtmlUnitDriver() {
                @Override
                protected WebClient getWebClient() {
                    WebClient webClient = super.getWebClient();
                    WebClientOptions options = webClient.getOptions();
                    options.setThrowExceptionOnFailingStatusCode(false);
                    options.setThrowExceptionOnScriptError(false);
                    options.setPrintContentOnFailingStatusCode(false);
                    webClient.setCssErrorHandler(new SilentCssErrorHandler());
                    return webClient;
                }
            };
        } else if (browser.equalsIgnoreCase("safari")) {
            driver = new SafariDriver();
        } else {
            throw new Exception("Unsupported browser: " + browser);
        }

        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
            @Override
            public void run() {
                driver.quit();
            }
        }));

        if (maximized) {
            driver.manage().window().maximize();
        }

        if (!dryrun) {
            login();
        }
    }
}

From source file:org.arquillian.drone.appium.extension.webdriver.AppiumDriverFactory.java

License:Apache License

/**
 * Creates {@link Capabilities} instance with Chrome options set in case of Android and Chrome browser
 *
 * @param configuration/*from  w  w w  .  jav  a 2 s.  c  o m*/
 * @return {@link Capabilities} instance
 */
public Capabilities getCapabilities(WebDriverConfiguration configuration) {
    DesiredCapabilities capabilities = new DesiredCapabilities(configuration.getCapabilities());

    String browser = (String) capabilities.getCapability(MobileCapabilityType.BROWSER_NAME);
    if (browser != null)
        browser = browser.toLowerCase();

    // Set chromeOptions
    if (MobileBrowserType.CHROME.toLowerCase().equals(browser)) {
        ChromeOptions chromeOptions = new ChromeOptions();
        CapabilitiesOptionsMapper.mapCapabilities(chromeOptions, capabilities,
                ChromeDriverFactory.BROWSER_CAPABILITIES);
        capabilities.setCapability(AndroidMobileCapabilityType.CHROME_OPTIONS, chromeOptions);
    }

    return capabilities;
}

From source file:org.auraframework.integration.test.util.WebDriverTestCase.java

License:Apache License

/**
 * Adds capabilities that request WebDriver performance logs<br/>
 * See https://sites.google.com/a/chromium.org/chromedriver/logging/performance-log
 *///from w w  w .  j  a  v  a  2  s .c o m
private void addPerfCapabilities(DesiredCapabilities capabilities) {
    if (PerfUtil.hasPerfCmpTestAnnotation(this)) {
        // Do not reuse browser
        capabilities.setCapability(WebDriverProvider.REUSE_BROWSER_PROPERTY, false);
        LoggingPreferences performance_prefs = new LoggingPreferences();
        performance_prefs.enable(LogType.PERFORMANCE, Level.ALL);
        capabilities.setCapability(CapabilityType.LOGGING_PREFS, performance_prefs);
        Map<String, Object> prefs = new HashMap<>();
        prefs.put("traceCategories", "disabled-by-default-devtools.timeline");
        ChromeOptions options = new ChromeOptions();
        options.setExperimentalOption("perfLoggingPrefs", prefs);
        capabilities.setCapability(ChromeOptions.CAPABILITY, options);
    }
}

From source file:org.auraframework.test.util.WebDriverTestCase.java

License:Apache License

/**
 * Adds capabilities that request WebDriver performance logs<br/>
 * See https://sites.google.com/a/chromium.org/chromedriver/logging/performance-log
 *///w  ww .j ava  2s.  c om
private void addPerfCapabilities(DesiredCapabilities capabilities) {
    if (PerfUtil.hasPerfCmpTestAnnotation(this)) {
        LoggingPreferences performance_prefs = new LoggingPreferences();
        performance_prefs.enable(LogType.PERFORMANCE, Level.ALL);
        capabilities.setCapability(CapabilityType.LOGGING_PREFS, performance_prefs);
        Map<String, Object> prefs = new HashMap<>();
        prefs.put("traceCategories", "disabled-by-default-devtools.timeline");
        ChromeOptions options = new ChromeOptions();
        options.setExperimentalOption("perfLoggingPrefs", prefs);
        capabilities.setCapability(ChromeOptions.CAPABILITY, options);
    }
}