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.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 {//w w w .  j a  va  2  s  .co 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.google.caja.plugin.WebDriverHandle.java

License:Apache License

private static RemoteWebDriver makeDriver() {
    DesiredCapabilities dc = new DesiredCapabilities();

    String browserType = TestFlag.BROWSER.getString("firefox");

    if ("chrome".equals(browserType)) {
        // Chrome driver is odd in that the path to Chrome is specified
        // by a desiredCapability when you start a session. The other
        // browser drivers will read a java system property on start.
        // This applies to both remote Chrome and local Chrome.
        ChromeOptions chromeOpts = new ChromeOptions();
        String chromeBin = TestFlag.CHROME_BINARY.getString(null);
        if (chromeBin != null) {
            chromeOpts.setBinary(chromeBin);
        }//from w w w  . j  a  va2  s .  co m
        String chromeArgs = TestFlag.CHROME_ARGS.getString(null);
        if (chromeArgs != null) {
            String[] args = chromeArgs.split(";");
            chromeOpts.addArguments(args);
        }
        dc.setCapability(ChromeOptions.CAPABILITY, chromeOpts);
    }

    String url = TestFlag.WEBDRIVER_URL.getString("");

    if (!"".equals(url)) {
        dc.setBrowserName(browserType);
        dc.setJavascriptEnabled(true);
        try {
            return new RemoteWebDriver(new URL(url), dc);
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
    } else if ("chrome".equals(browserType)) {
        return new ChromeDriver(dc);
    } else if ("firefox".equals(browserType)) {
        return new FirefoxDriver();
    } else if ("safari".equals(browserType)) {
        // TODO(felix8a): local safari doesn't work yet
        return new SafariDriver();
    } else {
        throw new RuntimeException("No local driver for browser type '" + browserType + "'");
    }
}

From source file:com.griddynamics.cd.selenium.WebDriverFactory.java

License:Apache License

private DesiredCapabilities withChromeOptions(DesiredCapabilities capabilities) {
    if (!"chrome".equals(capabilities.getBrowserName())) {
        return capabilities;
    }//from   w ww.j  a v  a 2s.c  o m
    ChromeOptions options = new ChromeOptions();
    //required since Chrome 35, see https://code.google.com/p/chromedriver/issues/detail?id=799
    options.addArguments("test-type");
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);
    return capabilities;
}

From source file:com.kurento.kmf.test.client.BrowserClient.java

License:Open Source License

private void initDriver(String hostAddress) {
    Class<? extends WebDriver> driverClass = browser.getDriverClass();
    int hubPort = getProperty("test.hub.port", GridBrowserMediaApiTest.DEFAULT_HUB_PORT);

    try {/*from w ww  .j  a v  a 2s  .c o m*/
        if (driverClass.equals(FirefoxDriver.class)) {
            FirefoxProfile profile = new FirefoxProfile();
            // This flag avoids granting the access to the camera
            profile.setPreference("media.navigator.permission.disabled", true);
            if (remoteNode != null) {
                DesiredCapabilities capabilities = new DesiredCapabilities();
                capabilities.setCapability(FirefoxDriver.PROFILE, profile);
                capabilities.setBrowserName(DesiredCapabilities.firefox().getBrowserName());

                driver = new RemoteWebDriver(new URL("http://" + hostAddress + ":" + hubPort + "/wd/hub"),
                        capabilities);
            } else {
                driver = new FirefoxDriver(profile);
            }

            if (!usePhysicalCam && video != null) {
                launchFakeCam();
            }

        } else if (driverClass.equals(ChromeDriver.class)) {
            String chromedriver = null;
            if (SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_LINUX) {
                chromedriver = "chromedriver";
            } else if (SystemUtils.IS_OS_WINDOWS) {
                chromedriver = "chromedriver.exe";
            }
            System.setProperty("webdriver.chrome.driver",
                    new File("target/webdriver/" + chromedriver).getAbsolutePath());
            ChromeOptions options = new ChromeOptions();

            // This flag avoids grant the camera
            options.addArguments("--use-fake-ui-for-media-stream");

            // This flag avoids warning in chrome. See:
            // https://code.google.com/p/chromedriver/issues/detail?id=799
            options.addArguments("--test-type");

            if (!usePhysicalCam) {
                // This flag makes using a synthetic video (green with
                // spinner) in webrtc. Or it is needed to combine with
                // use-file-for-fake-video-capture to use a file faking the
                // cam
                options.addArguments("--use-fake-device-for-media-stream");

                if (video != null) {
                    options.addArguments("--use-file-for-fake-video-capture=" + video);

                    // Alternative: lauch fake cam also in Chrome
                    // launchFakeCam();
                }
            }

            if (remoteNode != null) {
                DesiredCapabilities capabilities = new DesiredCapabilities();
                capabilities.setCapability(ChromeOptions.CAPABILITY, options);
                capabilities.setBrowserName(DesiredCapabilities.chrome().getBrowserName());
                driver = new RemoteWebDriver(new URL("http://" + hostAddress + ":" + hubPort + "/wd/hub"),
                        capabilities);

            } else {
                driver = new ChromeDriver(options);
            }

        }
        driver.manage().timeouts().setScriptTimeout(timeout, TimeUnit.SECONDS);

    } catch (MalformedURLException e) {
        log.error("MalformedURLException in BrowserClient.initDriver", e);
    }
}

From source file:com.seleniumtests.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 .  j av a 2  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.getWebPlatform() != null) {
        capability.setPlatform(webDriverConfig.getWebPlatform());
    }

    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.seleniumtests.ut.browserfactory.TestAndroidCapabilitiesFactory.java

License:Apache License

/**
 * Check default behaviour//from  w  ww.  j ava 2s . c  o m
 */
@Test(groups = { "ut" })
public void testCreateDefaultAndroidBrowserCapabilities() {
    SeleniumTestsContext context = new SeleniumTestsContext(SeleniumTestsContextManager.getThreadContext());
    context.setBrowser(BrowserType.BROWSER.toString());
    context.setMobilePlatformVersion("8.0");
    context.setPlatform("android");
    context.setDeviceName("Samsung Galasy S8");
    context.setApp("");

    DriverConfig config = new DriverConfig(context);

    AndroidCapabilitiesFactory capaFactory = new AndroidCapabilitiesFactory(config);
    MutableCapabilities capa = capaFactory.createCapabilities();

    Assert.assertEquals(capa.getCapability(CapabilityType.BROWSER_NAME),
            BrowserType.BROWSER.toString().toLowerCase());
    Assert.assertNull(capa.getCapability(ChromeOptions.CAPABILITY));
    Assert.assertEquals(capa.getCapability(MobileCapabilityType.AUTOMATION_NAME), "Appium");
    Assert.assertEquals(capa.getCapability(MobileCapabilityType.PLATFORM_NAME), "android");
    Assert.assertEquals(capa.getCapability(MobileCapabilityType.PLATFORM_VERSION), "8.0");
    Assert.assertEquals(capa.getCapability(MobileCapabilityType.DEVICE_NAME), "Samsung Galasy S8");
    Assert.assertEquals(capa.getCapability(AndroidMobileCapabilityType.APP_PACKAGE), "com.infotel.mobile"); // from exampleConfigGenericParams.xml when tu.xml is executed, else, null
    Assert.assertEquals(capa.getCapability(AndroidMobileCapabilityType.APP_ACTIVITY),
            "com.infotel.mobile.StartActivity"); // from exampleConfigGenericParams.xml when tu.xml is executed, else, null
    Assert.assertNull(capa.getCapability(MobileCapabilityType.FULL_RESET));
}

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

License:Apache License

@Test(groups = { "ut" })
public void testCreateDefaultChromeCapabilities() {

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

    Assert.assertEquals(/*from  www . java 2  s  .com*/
            ((Map<?, ?>) (((ChromeOptions) capa).asMap().get(ChromeOptions.CAPABILITY))).get("args").toString(),
            "[--disable-translate, --disable-web-security, --no-sandbox]");
    Assert.assertEquals(capa.getCapability(CapabilityType.BROWSER_NAME), "chrome");
}

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

License:Apache License

@Test(groups = { "ut" })
public void testCreateChromeCapabilitiesOverrideUserAgent() {

    Mockito.when(config.getUserAgentOverride()).thenReturn("CHROME 55");

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

    Assert.assertEquals(/*from  ww w  .j  a va  2 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.seleniumtests.ut.browserfactory.TestChromeCapabilityFactory.java

License:Apache License

@Test(groups = { "ut" })
public void testCreateChromeCapabilitiesHeadless() {

    Mockito.when(config.isHeadlessBrowser()).thenReturn(true);

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

    Assert.assertEquals(/*ww  w.  ja va  2  s .c om*/
            ((Map<?, ?>) (((ChromeOptions) capa).asMap().get(ChromeOptions.CAPABILITY))).get("args").toString(),
            "[--disable-translate, --disable-web-security, --no-sandbox, --headless, --window-size=1280,1024, --disable-gpu]");
}

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

License:Apache License

/**
 * /*from   w  w w.ja  va2 s  .  co m*/
 */
@Test(groups = { "ut" })
public void testCreateChromeCapabilitiesOverrideBinPath() {

    Mockito.when(config.getMode()).thenReturn(DriverMode.LOCAL);
    Mockito.when(config.getChromeBinPath()).thenReturn("/opt/chrome/bin/chrome");

    // SeleniumTestsContext class adds a browserInfo when binary path is set
    Map<BrowserType, List<BrowserInfo>> updatedBrowserInfos = new HashMap<>();
    updatedBrowserInfos.put(BrowserType.CHROME,
            Arrays.asList(new BrowserInfo(BrowserType.CHROME, "72.0", "", false),
                    new BrowserInfo(BrowserType.CHROME, "73.0", "/opt/chrome/bin/chrome", false)));

    PowerMockito.when(OSUtility.getInstalledBrowsersWithVersion()).thenReturn(updatedBrowserInfos);

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

    Assert.assertEquals(((Map<?, ?>) (((ChromeOptions) capa).asMap().get(ChromeOptions.CAPABILITY)))
            .get("binary").toString(), "/opt/chrome/bin/chrome");
}