List of usage examples for org.openqa.selenium Platform is
public boolean is(Platform compareWith)
From source file:com.atlassian.selenium.browsers.firefox.DisplayAwareFirefoxChromeLauncher.java
License:Apache License
protected CommandLine prepareCommand(String... commands) { CommandLine command = new CommandLine(commands); command.setEnvironmentVariable("MOZ_NO_REMOTE", "1"); // don't set the library path on Snow Leopard Platform platform = Platform.getCurrent(); if (!platform.is(Platform.MAC) || ((platform.is(Platform.MAC)) && platform.getMajorVersion() <= 10 && platform.getMinorVersion() <= 5)) { command.setDynamicLibraryPath(browserInstallation.libraryPath()); }/* w w w . j a v a 2s . co m*/ if (System.getProperty("DISPLAY") != null) { command.setEnvironmentVariable("DISPLAY", System.getProperty("DISPLAY")); } return command; }
From source file:com.github.mike10004.seleniumhelp.UnitTests.java
License:Apache License
/** * Locates the firefox binary by platform. * <p>/* ww w . ja v a2 s . c o m*/ * Copied from Selenium's FirefoxBinary.java. See license above. */ @SuppressWarnings("deprecation") private static Stream<Executable> locateFirefoxBinariesFromPlatform() { ImmutableList.Builder<Executable> executables = new ImmutableList.Builder<>(); Platform current = Platform.getCurrent(); if (current.is(WINDOWS)) { executables.addAll(Stream .of(getPathsInProgramFiles("Mozilla Firefox\\firefox.exe"), getPathsInProgramFiles("Firefox Developer Edition\\firefox.exe"), getPathsInProgramFiles("Nightly\\firefox.exe")) .flatMap(List::stream).map(File::new).filter(File::exists).map(Executable::new) .collect(toList())); } else if (current.is(MAC)) { // system File binary = new File("/Applications/Firefox.app/Contents/MacOS/firefox-bin"); if (binary.exists()) { executables.add(new Executable(binary)); } // user home binary = new File(System.getProperty("user.home") + binary.getAbsolutePath()); if (binary.exists()) { executables.add(new Executable(binary)); } } else if (current.is(UNIX)) { String systemFirefoxBin = new ExecutableFinder().find("firefox-bin"); if (systemFirefoxBin != null) { executables.add(new Executable(new File(systemFirefoxBin))); } } String systemFirefox = new ExecutableFinder().find("firefox"); if (systemFirefox != null) { Path firefoxPath = new File(systemFirefox).toPath(); if (Files.isSymbolicLink(firefoxPath)) { try { Path realPath = firefoxPath.toRealPath(); File attempt1 = realPath.getParent().resolve("firefox").toFile(); if (attempt1.exists()) { executables.add(new Executable(attempt1)); } else { File attempt2 = realPath.getParent().resolve("firefox-bin").toFile(); if (attempt2.exists()) { executables.add(new Executable(attempt2)); } } } catch (IOException e) { // ignore this path } } else { executables.add(new Executable(new File(systemFirefox))); } } return executables.build().stream(); }
From source file:com.opera.core.systems.OperaDriverTestRunner.java
License:Apache License
/** * Determines whether a test should be ignored or not based on a JUnit ignore annotation rule. The * check for this is mutually exclusive, meaning that if <em>either</em> the product or the * platform is true, the test will be ignored. * * @param ignoreAnnotation a custom ignore annotation * @return true if test should be ignored, false otherwise *//* w w w .j a v a 2 s . c o m*/ private boolean shouldIgnore(Ignore ignoreAnnotation) { if (ignoreAnnotation == null) { return false; } // If it's a plain old @Ignore without arguments if (ignoreAnnotation.products().length == 0 && ignoreAnnotation.platforms().length == 0) { return true; } for (OperaProduct product : ignoreAnnotation.products()) { if (product.is(OperaProduct.ALL)) { break; } else if (product.is(OperaDriverTestCase.currentProduct)) { return true; } } for (Platform platform : ignoreAnnotation.platforms()) { if (platform.is(Platform.ANY)) { return true; //} else if (OperaDriverTestCase.currentPlatform.is(platform)) { } else if (platform.is(OperaDriverTestCase.currentPlatform)) { return true; } } // Should not be ignored, none of the rules apply return false; }
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 ww w. j av a 2s .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.opera.core.systems.testing.IgnoreComparator.java
License:Apache License
public boolean shouldIgnore(Ignore annotation) { if (annotation == null) { return false; }//from w w w .j a v a 2 s . c o m for (Platform platform : annotation.platforms()) { if (platform.is(currentPlatform)) { for (OperaProduct product : annotation.products()) { if (product.is(currentProduct)) { return true; } } } } return false; }
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 *//*ww w.ja v a2 s. c om*/ 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:crazy.seleiumTools.ProfilesIni.java
License:Apache License
public File locateAppDataDirectory(Platform os) { File appData;// w w w . j a va 2 s .co m if (os.is(WINDOWS)) { appData = new File(MessageFormat.format("{0}\\Mozilla\\Firefox", System.getenv("APPDATA"))); } else if (os.is(MAC)) { appData = new File( MessageFormat.format("{0}/Library/Application Support/Firefox", System.getenv("HOME"))); } else { appData = new File(MessageFormat.format("{0}/.mozilla/firefox", System.getenv("HOME"))); } if (!appData.exists()) { // It's possible we're being run as part of an automated build. // Assume the user knows what they're doing return null; } if (!appData.isDirectory()) { throw new WebDriverException("The discovered user firefox data directory " + "(which normally contains the profiles) isn't a directory: " + appData.getAbsolutePath()); } return appData; }
From source file:io.appium.java_client.localserver.ServerBuilderTest.java
License:Apache License
private static File findCustomNode() { Platform current = Platform.getCurrent(); if (current.is(Platform.WINDOWS)) return new File(String.valueOf(properties.get("path.to.custom.node.win"))); if (current.is(Platform.MAC)) return new File(String.valueOf(properties.get("path.to.custom.node.macos"))); return new File(String.valueOf(properties.get("path.to.custom.node.linux"))); }
From source file:org.jitsi.meet.test.pageobjects.base.TestHint.java
License:Apache License
/** * On Android the {@link TestHint}'s key is defined in * the react-native's 'accessibilityLabel', but on iOS the react-native's * 'testID' attribute is used. That's because 'testID' does not work as * expected on Android and the 'accessibilityLabel' works in a different way * on iOS than on Android...// w w w . j av a 2 s . c om * * @return {@code true} if {@link TestHint} should be located by * the accessibility id or {@code false} if the id based search should be * used. */ private boolean useAccessibilityForId() { Platform driversPlatform = driver.getCapabilities().getPlatform(); // FIXME This looks like a bug, but I don't want to deal with this right // now. // Not sure if it's only when running appium from source or does it // sometimes report Android as LINUX platform. Also iOS is translated to // MAC ??? return driversPlatform.is(Platform.ANDROID) || driversPlatform.is(Platform.LINUX); }
From source file:org.openqa.grid.internal.utils.DefaultCapabilityMatcher.java
License:Apache License
public boolean matches(Map<String, Object> nodeCapability, Map<String, Object> requestedCapability) { if (nodeCapability == null || requestedCapability == null) { return false; }/*www . jav a 2 s .co m*/ for (String key : requestedCapability.keySet()) { // ignore capabilities that are targeted at grid internal for the // matching // TODO freynaud only consider version, browser and OS for now if (!key.startsWith(GRID_TOKEN) && toConsider.contains(key)) { if (requestedCapability.get(key) != null) { String value = requestedCapability.get(key).toString(); if (!("ANY".equalsIgnoreCase(value) || "".equals(value) || "*".equals(value))) { Platform requested = extractPlatform(requestedCapability.get(key)); // special case for platform if (requested != null) { Platform node = extractPlatform(nodeCapability.get(key)); if (node == null) { return false; } if (!node.is(requested)) { return false; } } else { if (!requestedCapability.get(key).equals(nodeCapability.get(key))) { return false; } } } else { // null value matches anything. } } } } return true; }