Example usage for org.openqa.selenium Capabilities is

List of usage examples for org.openqa.selenium Capabilities is

Introduction

In this page you can find the example usage for org.openqa.selenium Capabilities is.

Prototype

default boolean is(String capabilityName) 

Source Link

Usage

From source file:com.atlassian.selenium.browsers.firefox.DisplayAwareFirefoxLauncher.java

License:Apache License

public DisplayAwareFirefoxLauncher(Capabilities browserOptions, RemoteControlConfiguration configuration,
        String sessionId, String browserLaunchLocation) throws InvalidBrowserExecutableException {
    String browserName = BrowserType.FIREFOX;
    BrowserLocator locator = new CombinedFirefoxLocator();
    String version = (String) browserOptions.getCapability(CapabilityType.VERSION);
    if ("2".equals(version)) {
        browserName = BrowserType.FIREFOX_2;
        locator = new Firefox2Locator();
    }/*from  w  w w.j  a va2  s .c o m*/
    if ("3".equals(version)) {
        browserName = BrowserType.FIREFOX_3;
        locator = new Firefox3Locator();
    }
    String mode = (String) browserOptions.getCapability("mode");
    if (mode == null) {
        mode = "chrome";
    }
    if ("default".equals(mode)) {
        mode = "chrome";
    }

    BrowserInstallation installation = ApplicationRegistry.instance().browserInstallationCache()
            .locateBrowserInstallation(browserName, browserLaunchLocation, locator);

    if (installation == null) {
        throw new InvalidBrowserExecutableException("The specified path to the browser executable is invalid.");
    }

    if ("chrome".equals(mode)) {
        realLauncher = new DisplayAwareFirefoxChromeLauncher(browserOptions, configuration, sessionId,
                installation);
        return;
    }

    boolean proxyInjectionMode = browserOptions.is("proxyInjectionMode") || "proxyInjection".equals(mode);

    // You can't just individually configure a browser for PI mode; it's a server-level
    // configuration parameter
    boolean globalProxyInjectionMode = configuration.getProxyInjectionModeArg();
    if (proxyInjectionMode && !globalProxyInjectionMode) {
        if (proxyInjectionMode) {
            throw new RuntimeException(
                    "You requested proxy injection mode, but this server wasn't configured with -proxyInjectionMode on the command line");
        }
    }

    // if user didn't request PI, but the server is configured that way, just switch up to PI
    proxyInjectionMode = globalProxyInjectionMode;
    if (proxyInjectionMode) {
        realLauncher = new ProxyInjectionFirefoxCustomProfileLauncher(browserOptions, configuration, sessionId,
                installation);
        return;
    }

    // the mode isn't "chrome" or "proxyInjection"; at this point it had better be
    // CapabilityType.PROXY
    if (!CapabilityType.PROXY.equals(mode)) {
        throw new RuntimeException("Unrecognized browser mode: " + mode);
    }

    realLauncher = new FirefoxCustomProfileLauncher(browserOptions, configuration, sessionId, installation);

}

From source file:com.thoughtworks.selenium.corebased.TestClickAt.java

License:Apache License

private boolean isUsingNativeEvents() {
    if (!(selenium instanceof WrapsDriver)) {
        return false;
    }//from ww w  .  j av  a 2 s  .c om

    WebDriver driver = ((WrapsDriver) selenium).getWrappedDriver();
    if (!(driver instanceof HasCapabilities)) {
        return false;
    }

    Capabilities capabilities = ((HasCapabilities) driver).getCapabilities();
    return capabilities.is(CapabilityType.HAS_NATIVE_EVENTS);
}

From source file:org.arquillian.drone.browserstack.extension.webdriver.BrowserStackDriverFactory.java

License:Apache License

@Override
public BrowserStackDriver createInstance(WebDriverConfiguration configuration) {
    Capabilities capabilities = configuration.getCapabilities();
    String url = (String) capabilities.getCapability(URL);
    String accessKey = null;/*from  ww  w. ja  va 2 s . co  m*/

    if (Utils.isNullOrEmpty(url)) {
        String username = (String) capabilities.getCapability(USERNAME);
        accessKey = (String) capabilities.getCapability(ACCESS_KEY);

        if (Utils.isNullOrEmpty(accessKey)) {
            accessKey = (String) capabilities.getCapability("automate.key");
        }
        if (Utils.isNullOrEmpty(username) || Utils.isNullOrEmpty(accessKey)) {
            throw new IllegalArgumentException(
                    "You have to specify either an username and an access.key or the whole url in your arquillian descriptor");

        } else {
            url = "http://" + username + ":" + accessKey + "@hub.browserstack.com/wd/hub";
        }
    }

    try {
        URL browserStackUrl = new URL(url);

        boolean isSetBrowserStackLocal = capabilities.is(BROWSERSTACK_LOCAL);
        boolean isSetBrowserStackLocalManaged = capabilities.is(BROWSERSTACK_LOCAL_MANAGED);

        if (isSetBrowserStackLocal && isSetBrowserStackLocalManaged) {
            if (Utils.isNullOrEmpty(accessKey)) {
                accessKey = url.substring(url.lastIndexOf(":") + 1, url.indexOf("@"));
            }
            String additionalArgs = (String) capabilities.getCapability(BROWSERSTACK_LOCAL_ARGS);
            String localBinary = (String) capabilities.getCapability(BROWSERSTACK_LOCAL_BINARY);

            BrowserStackLocalRunner.getBrowserStackLocalInstance().runBrowserStackLocal(accessKey,
                    additionalArgs, localBinary);
        }

        return new BrowserStackDriver(browserStackUrl, capabilities, isSetBrowserStackLocal,
                isSetBrowserStackLocalManaged);
    } catch (MalformedURLException e) {
        throw new IllegalArgumentException(
                "The BrowserStack url: " + url + " has been detected as a malformed URL. ", e);
    }
}

From source file:org.arquillian.drone.saucelabs.extension.webdriver.SauceLabsDriverFactory.java

License:Apache License

@Override
public SauceLabsDriver createInstance(WebDriverConfiguration configuration) {
    Capabilities capabilities = configuration.getCapabilities();
    String url = (String) capabilities.getCapability(URL);
    String username = null;//  www  .  ja v  a  2s . c om
    String accessKey = null;

    if (Utils.isNullOrEmpty(url)) {
        username = (String) capabilities.getCapability(USERNAME);
        accessKey = (String) capabilities.getCapability(ACCESS_KEY);
        if (accessKey == null) {
            accessKey = (String) capabilities.getCapability("automate.key");
        }

        if (Utils.isNullOrEmpty(username) || Utils.isNullOrEmpty(accessKey)) {
            throw new IllegalArgumentException(
                    "You have to specify either an username and an access.key or the whole url in your arquillian descriptor");
        } else {
            url = "http://" + username + ":" + accessKey + "@ondemand.saucelabs.com:80/wd/hub";
        }
    }

    try {
        URL sauceConnectUrl = new URL(url);
        boolean isSetSauceConnectManaged = capabilities.is(SAUCE_CONNECT_MANAGED);

        if (isSetSauceConnectManaged) {
            if (Utils.isNullOrEmpty(accessKey)) {
                username = url.substring(url.lastIndexOf("://") + 3, url.indexOf(":"));
                accessKey = url.substring(url.lastIndexOf(":") + 1, url.indexOf("@"));
            }

            String additionalArgs = (String) capabilities.getCapability(SAUCE_CONNECT_ARGS);
            String localBinary = (String) capabilities.getCapability(SAUCE_CONNECT_BINARY);

            SauceConnectRunner.getSauceConnectRunnerInstance().runSauceConnect(username, accessKey,
                    additionalArgs, localBinary);
        }

        return new SauceLabsDriver(sauceConnectUrl, capabilities, isSetSauceConnectManaged);
    } catch (MalformedURLException e) {
        throw new IllegalArgumentException(
                "The BrowserStack url: " + url + " has been detected as a malformed URL. ", e);
    }
}

From source file:org.auraframework.test.AdaptiveWebElementDriver.java

License:Apache License

public AdaptiveWebElementDriver(CommandExecutor executor, Capabilities desiredCapabilities,
        Capabilities requiredCapabilities) {
    super(executor, desiredCapabilities, requiredCapabilities);

    // Unless you explicitly request a "default" driver, return a driver that returns AdaptiveWebElements
    if (!((desiredCapabilities != null && desiredCapabilities.is(DEFAULT_CAPABILITY))
            || (requiredCapabilities != null && requiredCapabilities.is(DEFAULT_CAPABILITY)))) {
        this.setElementConverter(new AdaptiveWebElement.JsonConverter(this));
    }/*from w ww .j a va 2s  . c  o  m*/
}

From source file:org.xframium.device.cloud.CloudDescriptor.java

License:Open Source License

/**
* Gets the cloud url.//w  w  w  .j  a  v a 2 s .  c  o  m
*
* @return the cloud url
*/
public String getCloudUrl(Capabilities c) {

    try {
        if (provider != null && provider.name != null && provider.name.equals("PERFECTO")) {
            if (c.is("perfectoFastWeb"))
                return "https://" + URLEncoder.encode(getUserName(), "UTF-8") + ":"
                        + URLEncoder.encode(getPassword(), "UTF-8") + "@" + getHostName()
                        + "/nexperience/perfectomobile/wd/hub/fast";
            else
                return "https://" + URLEncoder.encode(getUserName(), "UTF-8") + ":"
                        + URLEncoder.encode(getPassword(), "UTF-8") + "@" + getHostName()
                        + "/nexperience/perfectomobile/wd/hub";
        } else if (provider != null && provider.name != null && provider.name.equals("BROWSERSTACK"))
            return "https://" + URLEncoder.encode(getUserName(), "UTF-8") + ":"
                    + URLEncoder.encode(getPassword(), "UTF-8") + "@" + getHostName() + "/wd/hub";
        else if (provider != null && provider.name != null && provider.name.equals("SAUCELABS"))
            return "http://" + URLEncoder.encode(getUserName(), "UTF-8") + ":"
                    + URLEncoder.encode(getPassword(), "UTF-8") + "@" + getHostName() + "/wd/hub";
        else if (provider != null && provider.name != null && provider.name.equals("WINDOWS"))
            return "http://" + URLEncoder.encode(getUserName(), "UTF-8") + ":"
                    + URLEncoder.encode(getPassword(), "UTF-8") + "@" + getHostName();
        else {
            if (getUserName() == null || getUserName().isEmpty() || getUserName().equals("null"))
                return "http://" + getHostName() + "/wd/hub";
            else
                return "https://" + URLEncoder.encode(getUserName(), "UTF-8") + ":"
                        + URLEncoder.encode(getPassword(), "UTF-8") + "@" + getHostName() + "/wd/hub";
        }

    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return null;

}