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

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

Introduction

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

Prototype

String CAPABILITY

To view the source code for org.openqa.selenium.chrome ChromeOptions CAPABILITY.

Click Source Link

Document

Key used to store a set of ChromeOptions in a Capabilities object.

Usage

From source file:com.seleniumtests.ut.browserfactory.TestChromeCapabilityFactory.java

License:Apache License

/**
 * Check mobile capabilities does not share the desktop capabilities
 *//*  ww  w . j  ava 2s  . c  om*/
@Test(groups = { "ut" })
public void testCreateDefaultMobileCapabilities() {

    Mockito.when(config.isEnableJavascript()).thenReturn(true);
    Mockito.when(config.getProxy()).thenReturn(proxyConfig);

    MutableCapabilities capa = new ChromeCapabilitiesFactory(config).createMobileCapabilities(config);

    Assert.assertNull(capa.getCapability(CapabilityType.SUPPORTS_JAVASCRIPT));
    Assert.assertNull(capa.getCapability(CapabilityType.TAKES_SCREENSHOT));
    Assert.assertNull(capa.getCapability(CapabilityType.ACCEPT_SSL_CERTS));
    Assert.assertEquals(((Map<?, ?>) capa.getCapability(ChromeOptions.CAPABILITY)).get("args").toString(),
            "[--disable-translate, --disable-web-security]");
}

From source file:com.seleniumtests.ut.browserfactory.TestChromeCapabilityFactory.java

License:Apache License

@Test(groups = { "ut" })
public void testCreateMobileCapabilitiesOverrideUserAgent() {
    Mockito.when(config.getUserAgentOverride()).thenReturn("CHROME 55");

    MutableCapabilities capa = new ChromeCapabilitiesFactory(config).createCapabilities();

    Assert.assertEquals(/*from www .j a v  a2  s.  c o m*/
            ((Map<?, ?>) (((ChromeOptions) capa).asMap().get(ChromeOptions.CAPABILITY))).get("args").toString(),
            "[--user-agent=CHROME 55, --disable-translate, --disable-web-security, --no-sandbox]");
}

From source file:com.stratio.qa.specs.HookGSpec.java

License:Apache License

/**
 * Connect to selenium.//w ww  . j  a v  a  2s .co  m
 *
 * @throws MalformedURLException
 */
@Before(order = ORDER_10, value = { "@mobile,@web" })
public void seleniumSetup() throws MalformedURLException {
    String grid = System.getProperty("SELENIUM_GRID");
    if (grid == null) {
        fail("Selenium grid not available");
    }
    String b = ThreadProperty.get("browser");

    if ("".equals(b)) {
        fail("Non available browsers");
    }

    String browser = b.split("_")[0];
    String version = b.split("_")[1];
    commonspec.setBrowserName(browser);
    commonspec.getLogger().debug("Setting up selenium for {}", browser);

    DesiredCapabilities capabilities = null;

    switch (browser.toLowerCase()) {
    case "chrome":
        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.addArguments("--no-sandbox");
        chromeOptions.addArguments("--ignore-certificate-errors");
        capabilities = DesiredCapabilities.chrome();
        capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
        break;
    case "firefox":
        capabilities = DesiredCapabilities.firefox();
        break;
    case "phantomjs":
        capabilities = DesiredCapabilities.phantomjs();
        break;
    case "iphone":
    case "safari":
        capabilities = DesiredCapabilities.iphone();
        capabilities.setCapability("platformName", "iOS");
        capabilities.setCapability("platformVersion", "8.1");
        capabilities.setCapability("deviceName", "iPhone Simulator");
        break;
    case "android":
        capabilities = DesiredCapabilities.android();
        capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("platformVersion", "6.0");
        capabilities.setCapability("deviceName", "Android Emulator");
        capabilities.setCapability("app", "Browser");
        break;
    default:
        commonspec.getLogger().error("Unknown browser: " + browser);
        throw new SeleniumException("Unknown browser: " + browser);
    }

    capabilities.setVersion(version);

    grid = "http://" + grid + "/wd/hub";
    HttpClient.Factory factory = new ApacheHttpClient.Factory(new HttpClientFactory(60000, 60000));
    HttpCommandExecutor executor = new HttpCommandExecutor(new HashMap<String, CommandInfo>(), new URL(grid),
            factory);
    commonspec.setDriver(new RemoteWebDriver(executor, capabilities));
    commonspec.getDriver().manage().timeouts().pageLoadTimeout(PAGE_LOAD_TIMEOUT, TimeUnit.SECONDS);
    commonspec.getDriver().manage().timeouts().implicitlyWait(IMPLICITLY_WAIT, TimeUnit.SECONDS);
    commonspec.getDriver().manage().timeouts().setScriptTimeout(SCRIPT_TIMEOUT, TimeUnit.SECONDS);

    commonspec.getDriver().manage().deleteAllCookies();
    if (capabilities.getCapability("deviceName") == null) {
        commonspec.getDriver().manage().window().setSize(new Dimension(1440, 900));
    }
    commonspec.getDriver().manage().window().maximize();

}

From source file:com.tascape.qa.th.webui.comm.Chrome.java

License:Apache License

public Chrome() {
    String chromeServer = System.getProperty(SYSPROP_CHROME_DRIVER);
    if (chromeServer == null) {
        throw new RuntimeException("Cannot find system property " + SYSPROP_CHROME_DRIVER);
    }/*w ww  .  jav  a 2  s . c  om*/

    ChromeOptions options = new ChromeOptions();
    options.addArguments(Arrays.asList("allow-running-insecure-content", "ignore-certificate-errors"));
    //options.addExtensions(new File("/path/to/extension.crx"));
    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);

    super.setWebDriver(new ChromeDriver(capabilities));
}

From source file:com.thjug.bgile.webdriver.DefaultWebDriverProvider.java

License:Creative Commons License

@Override
protected ChromeDriver createChromeDriver() {
    final DesiredCapabilities dc = DesiredCapabilities.chrome();
    final String[] cmdOptions = { "--ignore-certificate-errors" };
    dc.setCapability("chrome.switches", Arrays.asList(cmdOptions));

    final ChromeOptions options = new ChromeOptions();
    options.addArguments("test-type");
    dc.setCapability(ChromeOptions.CAPABILITY, options);
    return new ChromeDriver(dc);
}

From source file:com.worldline.easycukes.selenium.WebDriverFactory.java

License:Open Source License

/**
 * Allows to customize and configure the options of a chrome session
 *
 * @return DesiredCapabilities/*from  ww w . j a  v  a2s.  co  m*/
 */
private static DesiredCapabilities chromeCapabilities() {
    final DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    final ChromeOptions options = new ChromeOptions();
    options.addArguments("--test-type");
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);
    return capabilities;
}

From source file:contentspeed.RunSiteTest.java

public static void main(String[] args) {

    try {/*ww w  .  j a  v  a 2 s .c o m*/

        System.setProperty("webdriver.chrome.driver",
                "D:\\Documentatie\\Selenium\\ChromeDriver\\chromedriver234.exe");

        ChromeOptions optionsChrome = new ChromeOptions();

        optionsChrome.addArguments("--start-maximized");

        DesiredCapabilities caps = new DesiredCapabilities();
        caps.setCapability("browser", "Chrome");
        caps.setCapability("chrome.switches", "--start-maximized");

        caps.setCapability("os", "Windows");
        caps.setCapability("os_version", "10");
        caps.setCapability("resolution", "1366x768");
        caps.setCapability(ChromeOptions.CAPABILITY, optionsChrome);

        driver = new ChromeDriver(caps);

        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

        driver.get(Constants.URLProdus);

        objProdus = new ProdusCeai(driver);

        objProdus.Actions("Anda", "Cristea", "andadeacu2@yahoo.com", "0741010736", "Bucuresti", "Bucuresti",
                "strada Fericirii nr. 9", "observatii test      ");

        //driver.quit();

    } catch (WebDriverException ex) {

        ex.printStackTrace();

        //driver.quit();

    }
}

From source file:de.knowwe.uitest.UITestUtils.java

License:Open Source License

public static RemoteWebDriver setUp(String browser, String testClassName, Platform os, WikiTemplate template,
        String testName, boolean devMode) throws IOException, InterruptedException {

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.BROWSER_NAME, browser);
    String chromeBinary = System.getProperty("knowwe.chrome.binary");
    if (chromeBinary != null) {
        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.setBinary(chromeBinary);
        capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
    }/* w  ww.j av  a  2  s  . c  om*/

    RemoteWebDriver driver;
    if (devMode) {
        driver = new RemoteWebDriver(new URL("http://localhost:9515"), capabilities);
    } else {
        capabilities.setCapability("name", testClassName);
        capabilities.setCapability("platform", os);
        driver = new RemoteWebDriver(
                new URL("http://d3web:8c7e5a48-56dd-4cde-baf0-b17f83803044@ondemand.saucelabs.com:80/wd/hub"),
                capabilities);
    }
    driver.manage().window().setSize(new Dimension(1024, 768));
    driver.get(UITestUtils.getKnowWEUrl(template, "Main", devMode));
    if (!UITestUtils.isLoggedIn(driver, template)) {
        UITestUtils.logIn(driver, "UiTest", "fyyWWyVeHzzHfkUMZxUQ?3nDBPbTT6", NORMAL_PAGE, template);
    }
    driver.get(getKnowWEUrl(template, testName, devMode));
    if (!pageExists(template, driver)) {
        createDummyPage(template, 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  w w  .j a  v  a 2s  . com*/
    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:facebookfriendsoffriends.FacebookFriendsOfFriends.java

/**
 * @param args the command line arguments
 *//* ww  w .  j a  v  a2  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);
}