Example usage for org.openqa.selenium Platform fromString

List of usage examples for org.openqa.selenium Platform fromString

Introduction

In this page you can find the example usage for org.openqa.selenium Platform fromString.

Prototype

public static Platform fromString(String name) 

Source Link

Document

Gets a platform with the name matching the parameter.

Usage

From source file:com.github.licanhua.test.framework.config.AbstractConfiguration.java

License:Apache License

public DesiredCapabilities getDesiredCapabilities(String browserName) {

    String path = Const.BROWSER_CONFIG_DIR + browserName + ".properties";

    Properties properties = ConfigurationHelper.load(path);

    String version = getString(Const.BROWSER_VERSION, Const.DEFAULT_BROWSER_VERSION);
    String platform = getString(Const.BROWSER_PLATFORM, Const.DEFAULT_BROWSER_PLATFORM);

    DesiredCapabilities caps = new DesiredCapabilities(browserName, version, Platform.fromString(platform));
    for (Object key : properties.keySet()) {
        caps.setCapability((String) key, properties.get(key));
    }//from w  w w .  ja  v a 2 s.  c  o m

    return caps;
}

From source file:com.rmn.qa.AutomationUtils.java

License:Open Source License

/**
 * Returns the Selenium platform object from an unknown object, which could be a string or an actual object.
 * If the platform can not be determined, null will be returned
 * @param platformObj// w ww. j a v a  2s . com
 * @return
 */
public static Platform getPlatformFromObject(Object platformObj) {
    if (platformObj == null) {
        return null;
    }
    Platform parsedPlatform = null;
    if (platformObj instanceof Platform) {
        parsedPlatform = ((Platform) platformObj);
    } else if (platformObj instanceof String) {
        String platformString = (String) platformObj;
        if (StringUtils.isEmpty(platformString)) {
            return null;
        }
        try {
            parsedPlatform = Platform.fromString(platformString);
        } catch (WebDriverException e) {
            log.error("Error parsing out platform for string: " + platformObj, e);
        }
    } else {
        // Do nothing and return null for unexpected type
        log.warn("Platform was not an expected type: " + platformObj);
    }
    return parsedPlatform;
}

From source file:com.seleniumtests.core.SeleniumTestsContext.java

License:Apache License

/**
 * From platform name, in case of Desktop platform, do nothing and in case of mobile, extract OS version from name
 * as platformName will be 'Android 5.0' for example
 *
 * @throws ConfigurationException    in mobile, if version is not present
 *///from   ww  w  . ja  va 2s  .  co  m
private void updatePlatformVersion() {
    try {
        Platform currentPlatform = Platform.fromString(getPlatform());
        if (currentPlatform.is(Platform.WINDOWS) || currentPlatform.is(Platform.MAC)
                || currentPlatform.is(Platform.UNIX)
                || currentPlatform.is(Platform.ANY) && getRunMode() == DriverMode.GRID) {
            return;

        } else {
            throw new WebDriverException("");
        }
    } catch (WebDriverException e) {
        if (getPlatform().toLowerCase().startsWith("android")
                || getPlatform().toLowerCase().startsWith("ios")) {
            String[] pfVersion = getPlatform().split(" ", 2);
            try {
                setPlatform(pfVersion[0]);
                setMobilePlatformVersion(pfVersion[1]);
                return;
            } catch (IndexOutOfBoundsException x) {
                setMobilePlatformVersion(null);
                logger.warn(
                        "For mobile platform, platform name should contain version. Ex: 'Android 5.0' or 'iOS 9.1'. Else, first found device is used");
            }

        } else {
            throw new ConfigurationException(
                    String.format("Platform %s has not been recognized as a valid platform", getPlatform()));
        }
    }
}

From source file:org.eclipse.packagedrone.testing.server.TestSuite.java

License:Open Source License

@BeforeClass
public static void startBrowser() throws MalformedURLException {
    if (SAUCE_USER_NAME != null) {
        driver = createSauce(Platform.fromString(SAUCE_PLATFORM), SAUCE_BROWSER, null);
    } else {/*from   ww w.  j  a  va2s  .  co  m*/
        // driver = new MarionetteDriver ();
        driver = new ChromeDriver();
    }
}

From source file:org.musetest.selenium.providers.ChromeDriverProvider.java

License:Open Source License

@Override
public WebDriver getDriver(SeleniumBrowserCapabilities capabilities, MuseExecutionContext context) {
    if (getOs() != null && !(OperatingSystem.get().equals(getOs())))
        return null; // this provider is not for the current OS

    if (!capabilities.getName().equals(BrowserType.CHROME))
        return null;

    File path = getDriverLocation(context);
    if (path == null) {
        context.raiseEvent(MessageEventType.create(
                "ChromeDriverProvider would try to satisfy request for Chrome browser, but it was not configured with a path to the driver"));
        return null;
    }//  w  w  w.j  a  v  a 2 s.c  om

    if (!(path.exists())) {
        context.raiseEvent(MessageEventType.create(
                "ChromeDriverProvider would try to satisfy request for Chrome browser, but the configured path does not exist: "
                        + path.getAbsolutePath()));
        return null;
    }

    synchronized (ChromeDriverProvider.class) {
        ChromeOptions options = new ChromeOptions();
        if (getArguments() != null)
            options.addArguments(getArguments());

        DesiredCapabilities desired = DesiredCapabilities.chrome();
        if (capabilities.getVersion() != null && capabilities.getVersion().length() > 0)
            desired.setVersion(capabilities.getVersion());
        if (capabilities.getPlatform() != null && capabilities.getPlatform().length() > 0)
            desired.setPlatform(Platform.fromString(capabilities.getPlatform()));
        options.merge(desired);

        System.setProperty("webdriver.chrome.driver", path.getAbsolutePath());
        return new ChromeDriver(options);
    }
}

From source file:org.musetest.selenium.providers.EdgeDriverProvider.java

License:Open Source License

@Override
public WebDriver getDriver(SeleniumBrowserCapabilities capabilities, MuseExecutionContext context) {
    if (getOs() != null && !(OperatingSystem.get().equals(getOs())))
        return null; // this provider is not for the current OS

    if (!capabilities.getName().equals(BrowserType.EDGE))
        return null;

    File path = getDriverLocation(context);
    if (path == null) {
        context.raiseEvent(MessageEventType.create(
                "EdgeDriverProvider would try to satisfy request for Firefox browser, but it was not configured with a path to the driver"));
        return null;
    }//from   ww w.  j a v  a  2s  .c om

    if (!(path.exists())) {
        context.raiseEvent(MessageEventType.create(
                "EdgeDriverProvider would try to satisfy request for Internet Explorer browser, but the configured path does not exist: "
                        + path.getAbsolutePath()));
        return null;
    }

    synchronized (EdgeDriverProvider.class) {

        DesiredCapabilities desired = DesiredCapabilities.edge();
        if (capabilities.getVersion() != null && capabilities.getVersion().length() > 0)
            desired.setVersion(capabilities.getVersion());
        if (capabilities.getPlatform() != null && capabilities.getPlatform().length() > 0)
            desired.setPlatform(Platform.fromString(capabilities.getPlatform()));

        EdgeOptions options = new EdgeOptions();
        options.merge(desired);
        if (getArguments() != null)
            LOG.error("Unable to set arguments for EdgeDriver: arguments are not supported by EdgeDriver");

        System.setProperty("webdriver.edge.driver", path.getAbsolutePath());
        return new EdgeDriver(options);
    }
}

From source file:org.musetest.selenium.providers.GeckoDriverProvider.java

License:Open Source License

@Override
public WebDriver getDriver(SeleniumBrowserCapabilities capabilities, MuseExecutionContext context) {
    if (getOs() != null && !(OperatingSystem.get().equals(getOs())))
        return null; // this provider is not for the current OS

    if (!capabilities.getName().equals(BrowserType.FIREFOX))
        return null;

    File path = getDriverLocation(context);
    if (path == null) {
        context.raiseEvent(MessageEventType.create(
                "GeckoDriverProvider would try to satisfy request for Firefox browser, but it was not configured with a path to the driver"));
        return null;
    }//from  w  w w  .j  av  a2  s. c  o m

    if (!(path.exists())) {
        context.raiseEvent(MessageEventType.create(
                "GeckoDriverProvider would try to satisfy request for Firefox browser, but the configured path does not exist: "
                        + path.getAbsolutePath()));
        return null;
    }

    synchronized (GeckoDriverProvider.class) {
        System.setProperty("webdriver.gecko.driver", path.getAbsolutePath());
        DesiredCapabilities selenium_capabilities = DesiredCapabilities.firefox();
        if (capabilities.getVersion() != null && capabilities.getVersion().length() > 0)
            selenium_capabilities.setVersion(capabilities.getVersion());
        if (capabilities.getPlatform() != null && capabilities.getPlatform().length() > 0)
            selenium_capabilities.setPlatform(Platform.fromString(capabilities.getPlatform()));
        selenium_capabilities.setCapability("marionette", true);
        FirefoxOptions options = new FirefoxOptions(selenium_capabilities);
        if (getArguments() != null)
            options.addArguments(getArguments());
        return new FirefoxDriver(options);
    }
}