Example usage for org.openqa.selenium Platform UNIX

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

Introduction

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

Prototype

Platform UNIX

To view the source code for org.openqa.selenium Platform UNIX.

Click Source Link

Document

Many platforms have UNIX traits, amongst them LINUX, Solaris and BSD.

Usage

From source file:com.opera.core.systems.OperaRunnerSettingsTest.java

License:Apache License

@Test
public void testSetDisplay() {
    Integer display = 8;/*w w w .  j a  va2s  .  com*/
    Exception unsupportedOperationException = null;

    try {
        settings.setDisplay(display);
    } catch (UnsupportedOperationException e) {
        unsupportedOperationException = e;
    }

    if (Platform.getCurrent() == Platform.WINDOWS) {
        assertNotNull(unsupportedOperationException);
    } else if (Platform.getCurrent() == Platform.LINUX || Platform.getCurrent() == Platform.UNIX) {
        assertNull(unsupportedOperationException);
        assertEquals(display, settings.getDisplay());
    }
}

From source file:com.opera.core.systems.runner.launcher.OperaLauncherRunnerSettings.java

License:Apache License

/**
 * Makes the launcher executable by chmod'ing the file at given path (GNU/Linux and Mac only).
 *
 * @param launcher the file to make executable
 *//*from  w  w w  .  ja  v  a 2  s  .c  o m*/
private static void makeLauncherExecutable(File launcher) {
    Platform current = Platform.getCurrent();

    if (current.is(Platform.UNIX) || current.is(Platform.MAC)) {
        CommandLine line = new CommandLine("chmod", "u+x", launcher.getAbsolutePath());
        line.execute();
    }
}

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

License:Open Source License

/**
 * Returns true if the platform is from the Unix family
 * @param platform/* w  w w .jav  a  2s .co m*/
 * @return
 */
public static boolean isPlatformUnix(Platform platform) {
    return getUnderlyingFamily(platform) == Platform.UNIX;
}

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

License:Open Source License

/**
 * Returns the underlying 'family' of the specified platform
 * @param platform//from w w w .  j a v  a  2 s .  c  o  m
 * @return
 */
public static Platform getUnderlyingFamily(Platform platform) {
    if (platform == null) {
        return null;
    }
    if (platform == Platform.UNIX || platform == Platform.WINDOWS || platform == Platform.MAC
            || platform == Platform.ANY) {
        return platform;
    } else {
        return getUnderlyingFamily(platform.family());
    }
}

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 w  w w .j  a  va2  s. c  o  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:edu.samplu.common.SauceLabsWebDriverHelper.java

License:Educational Community License

/**
 * Saucelabs setup//  ww  w  .  j a  va 2 s. c o m
 * @param className
 * @param testName
 * @throws Exception
 */
public void setUp(String className, String testName) throws Exception {
    if (System.getProperty(SAUCE_USER_PROPERTY) == null || System.getProperty(SAUCE_KEY_PROPERTY) == null) {
        Assert.fail("-D" + SAUCE_USER_PROPERTY + " and -D" + SAUCE_KEY_PROPERTY
                + " must be set to saucelabs user and access key.");
    }

    DesiredCapabilities capabilities = null;
    if ("ff".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) {
        capabilities = DesiredCapabilities.firefox();
    } else if ("ie".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) {
        capabilities = DesiredCapabilities.internetExplorer();
        capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
                true);
    } else if ("chrome".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) {
        capabilities = DesiredCapabilities.chrome();
    } else if ("opera".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) {
        capabilities = DesiredCapabilities.opera();
    } else if ("android".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) {
        capabilities = DesiredCapabilities.android();
    } else if ("safari".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) {
        capabilities = DesiredCapabilities.safari();
    } else if ("ipad".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) {
        capabilities = DesiredCapabilities.ipad();
    } else if ("iphone".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) {
        capabilities = DesiredCapabilities.iphone();
    } else {
        capabilities = DesiredCapabilities.firefox();
    }

    String version = System.getProperty(SAUCE_VERSION_PROPERTY);
    if (version != null && "0".equals(version)) { // Blank or 0 leaves version blank for use with chrome

        if (!"chrome".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) {
            throw new RuntimeException("Blank or 0 version for a browser not chrome "
                    + System.getProperty(SAUCE_BROWSER_PROPERTY));
        }

        capabilities.setCapability("version", version);
    }

    capabilities.setCapability("platform",
            System.getProperty(SAUCE_PLATFORM_PROPERTY, Platform.UNIX.toString()).replaceAll("_", " "));
    capabilities.setCapability("idle-timeout", 180);
    capabilities.setCapability("max-duration", 480);
    capabilities.setCapability("name", className + "." + testName + "-" + ITUtil.DTS);
    capabilities.setCapability("disable-popup-handler", System.getProperty(SAUCE_POPUP_PROPERTY, "false"));
    capabilities.setCapability("public", System.getProperty(SAUCE_SHARE_PROPERTY, "share"));

    this.driver = new RemoteWebDriver(new URL("http://" + authentication.getUsername() + ":"
            + authentication.getAccessKey() + "@ondemand.saucelabs.com:80/wd/hub"), capabilities);
    this.sessionId = ((RemoteWebDriver) driver).getSessionId().toString();

    // TODO it would be better to do these at tear down, passing state could then be included in names, but requires more parameters
    try {
        String dir = determineSaveDir(className, testName);
        String resources = "mkdir " + dir + " ; cd " + dir + " ; \n"
                + curlSaveResourceString(className, testName, "selenium-server.log") + " ; \n"
                + curlSaveResourceString(className, testName, "video.flv") + " ; \n"
                + wgetnSaveResourceString(className, testName) + " ; \n" + "cd ../\n";
        System.out.println(resources);
        writeFile("SauceLabsResources" + dir + ".sh", resources);
    } catch (Exception e) {
        System.out.println("Exception while writing SauceLabsResources.sh " + e.getMessage());
        System.out.println(curlSaveResourceString(className, testName, "selenium-server.log"));
        System.out.println(curlSaveResourceString(className, testName, "video.flv"));
        //            System.out.println(curlSaveResourceString(className, testName, "XXXXscreenshot.png (where XXXX is a number between 0000 and 9999)")); // TODO
    }
}

From source file:edu.samplu.common.SauceLabsWebDriverHelper.java

License:Educational Community License

private String deriveResourceBaseNames(String className, String testName, String resource) {
    return className + "." + testName + "-"
            + System.getProperty(SAUCE_PLATFORM_PROPERTY, Platform.UNIX.toString()) + "-"
            + System.getProperty(SAUCE_BROWSER_PROPERTY) + "-" + System.getProperty(SAUCE_VERSION_PROPERTY)
            + "-" + System.getProperty(WebDriverLegacyITBase.REMOTE_PUBLIC_USER_PROPERTY, "admin") + "-"
            + System.getProperty("rice.version", "unknown_build") + "-" + ITUtil.DTS + "-" + resource;
}

From source file:org.cerberus.serviceEngine.impl.SeleniumService.java

License:Open Source License

public DesiredCapabilities setCapabilityPlatform(DesiredCapabilities capabilities, String platform)
        throws CerberusException {
    if (platform.equalsIgnoreCase("WINDOWS")) {
        capabilities.setPlatform(Platform.WINDOWS);
    } else if (platform.equalsIgnoreCase("LINUX")) {
        capabilities.setPlatform(Platform.LINUX);
    } else if (platform.equalsIgnoreCase("ANDROID")) {
        capabilities.setPlatform(Platform.ANDROID);
    } else if (platform.equalsIgnoreCase("MAC")) {
        capabilities.setPlatform(Platform.MAC);
    } else if (platform.equalsIgnoreCase("UNIX")) {
        capabilities.setPlatform(Platform.UNIX);
    } else if (platform.equalsIgnoreCase("VISTA")) {
        capabilities.setPlatform(Platform.VISTA);
    } else if (platform.equalsIgnoreCase("WIN8")) {
        capabilities.setPlatform(Platform.WIN8);
    } else if (platform.equalsIgnoreCase("XP")) {
        capabilities.setPlatform(Platform.XP);
    } else {//from   w ww  .  j a  va2  s. co  m
        capabilities.setPlatform(Platform.ANY);
    }

    return capabilities;
}

From source file:org.kuali.rice.testtools.selenium.SauceLabsWebDriverHelper.java

License:Educational Community License

/**
 * <p>//from   ww  w. ja  v  a2 s.co  m
 * Saucelabs setUp.
 * </p><p>
 * Creates a {@link org.openqa.selenium.remote.RemoteWebDriver} instance with the DesiredCapabilities as configured
 * using the JVM arguments described as SAUCE_ Constants in this class.  After setUp the WebDriver can be accessed via
 * {@see #getDriver}.  You'll also need {@see #getSessionId} for when you call {@see #tearDown}
 * </p>
 *
 * @param className class name of the test being setup as a String
 * @param testName test name of the test being setup as a String
 * @throws Exception
 */
public void setUp(String className, String testName) throws Exception {
    if (System.getProperty(REMOTE_DRIVER_SAUCELABS_PROPERTY) == null) { // dup guard so WebDriverUtils doesn't have to be used.
        return;
    }

    if (System.getProperty(SAUCE_USER_PROPERTY) == null || System.getProperty(SAUCE_KEY_PROPERTY) == null) {
        Assert.fail("-D" + SAUCE_USER_PROPERTY + " and -D" + SAUCE_KEY_PROPERTY
                + " must be set to saucelabs user and access key.");
    }

    DesiredCapabilities capabilities = null;
    if ("ff".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) {
        capabilities = DesiredCapabilities.firefox();
    } else if ("ie".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) {
        capabilities = DesiredCapabilities.internetExplorer();
        capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
                System.getProperty(SAUCE_IE_INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS_PROPERTY, "true"));
    } else if ("chrome".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) {
        capabilities = DesiredCapabilities.chrome();
    } else if ("opera".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) {
        capabilities = DesiredCapabilities.opera();
    } else if ("android".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) {
        capabilities = DesiredCapabilities.android();
    } else if ("safari".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) {
        capabilities = DesiredCapabilities.safari();
    } else if ("ipad".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) {
        capabilities = DesiredCapabilities.ipad();
    } else if ("iphone".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) {
        capabilities = DesiredCapabilities.iphone();
    } else {
        capabilities = DesiredCapabilities.firefox();
    }

    String version = System.getProperty(SAUCE_VERSION_PROPERTY);
    if (version == null || "0".equals(version)) { // Blank or 0 leaves version blank for use with chrome

        if (!"chrome".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) {
            throw new RuntimeException("Blank or 0 version for a browser not chrome "
                    + System.getProperty(SAUCE_BROWSER_PROPERTY));
        }

        capabilities.setCapability("version", ""); // saucelabs requires blank for chrome (latest version)
    } else {
        capabilities.setCapability("version", version); // saucelabs requires blank for chrome (latest version)
    }

    capabilities.setCapability("platform",
            System.getProperty(SAUCE_PLATFORM_PROPERTY, Platform.UNIX.toString()).replaceAll("_", " "));
    capabilities.setCapability("idle-timeout",
            Integer.parseInt(System.getProperty(SAUCE_IDLE_TIMEOUT_SECONDS_PROPERTY, "180")));
    capabilities.setCapability("max-duration",
            Integer.parseInt(System.getProperty(SAUCE_MAX_DURATION_SECONDS_PROPERTY, "600")));
    capabilities.setCapability("name", className + "." + testName + "-" + AutomatedFunctionalTestUtils.DTS);
    capabilities.setCapability("disable-popup-handler", System.getProperty(SAUCE_POPUP_PROPERTY, "false"));
    capabilities.setCapability("public", System.getProperty(SAUCE_SHARE_PROPERTY, "public restricted"));

    System.out.println(
            "Requesting Saucelabs RemoteWebDriver with DesiredCapabilities of " + capabilities.toString());

    this.driver = new RemoteWebDriver(new URL("http://" + authentication.getUsername() + ":"
            + authentication.getAccessKey() + "@ondemand.saucelabs.com:80/wd/hub"), capabilities);
    this.sessionId = ((RemoteWebDriver) driver).getSessionId().toString();

    System.out.println("SauceLabs job can be viewed at https://saucelabs.com/jobs/" + this.sessionId);
}

From source file:org.kuali.rice.testtools.selenium.SauceLabsWebDriverHelper.java

License:Educational Community License

private String deriveResourceBaseNames(String className, String testName, String resource) {
    return className + "." + testName + "-"
            + System.getProperty(SAUCE_PLATFORM_PROPERTY, Platform.UNIX.toString()) + "-"
            + System.getProperty(SAUCE_BROWSER_PROPERTY) + "-" + System.getProperty(SAUCE_VERSION_PROPERTY)
            + "-" + System.getProperty(WebDriverUtils.REMOTE_PUBLIC_USER_PROPERTY, "admin") + "-"
            + System.getProperty(SAUCE_BUILD_PROPERTY, "unknown_build") + "-" + AutomatedFunctionalTestUtils.DTS
            + "-" + resource;
}