Java Code Examples for org.openqa.selenium.Platform#getCurrent()

The following examples show how to use org.openqa.selenium.Platform#getCurrent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FirefoxBinary.java    From selenium with Apache License 2.0 6 votes vote down vote up
public FirefoxBinary() {
  Executable systemBinary = locateFirefoxBinaryFromSystemProperty();
  if (systemBinary != null) {
    executable = systemBinary;
    return;
  }

  Executable platformBinary = locateFirefoxBinariesFromPlatform().findFirst().orElse(null);
  if (platformBinary != null) {
    executable = platformBinary;
    return;
  }

  throw new WebDriverException("Cannot find firefox binary in PATH. " +
                               "Make sure firefox is installed. OS appears to be: " + Platform.getCurrent());
}
 
Example 2
Source File: HttpClientTestBase.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldIncludeAUserAgentHeader() throws Exception {
  HttpResponse response = executeWithinServer(
      new HttpRequest(GET, "/foo"),
      new HttpServlet() {
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {
          try (Writer writer = resp.getWriter()) {
            writer.write(req.getHeader("user-agent"));
          }
        }
      });


  String label = new BuildInfo().getReleaseLabel();
  Platform platform = Platform.getCurrent();
  Platform family = platform.family() == null ? platform : platform.family();

  assertThat(string(response)).isEqualTo(String.format(
      "selenium/%s (java %s)",
      label,
      family.toString().toLowerCase()));
}
 
Example 3
Source File: JavaDriverTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void failsWhenRequestingANonJavaDriver() throws Throwable {
    DesiredCapabilities caps = new DesiredCapabilities("xjava", "1.0", Platform.getCurrent());
    try {
        driver = new JavaDriver(caps, caps);
        throw new MissingException(SessionNotCreatedException.class);
    } catch (SessionNotCreatedException e) {
    }
}
 
Example 4
Source File: JavaDriverTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void failsWhenRequestingUnsupportedCapability() throws Throwable {
    DesiredCapabilities caps = new DesiredCapabilities("java", "1.0", Platform.getCurrent());
    caps.setCapability("rotatable", true);
    try {
        driver = new JavaDriver(caps, caps);
        throw new MissingException(SessionNotCreatedException.class);
    } catch (SessionNotCreatedException e) {
    }
}
 
Example 5
Source File: JavaDriverTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void succeedsWhenRequestingNativeEventsCapability() throws Throwable {
    DesiredCapabilities caps = new DesiredCapabilities("java", "1.0", Platform.getCurrent());
    caps.setCapability("nativeEvents", true);
    driver = new JavaDriver(caps, caps);
    Capabilities capabilities = ((RemoteWebDriver) driver).getCapabilities();
    AssertJUnit.assertTrue(capabilities.is("nativeEvents"));
}
 
Example 6
Source File: JavaDriverTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void succeedsWhenRequestingNonNativeEventsCapability() throws Throwable {
    DesiredCapabilities caps = new DesiredCapabilities("java", "1.0", Platform.getCurrent());
    caps.setCapability("nativeEvents", false);
    driver = new JavaDriver(caps, caps);
    Capabilities capabilities = ((RemoteWebDriver) driver).getCapabilities();
    AssertJUnit.assertTrue(!capabilities.is("nativeEvents"));
}
 
Example 7
Source File: SeleniumDriver.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
public void launchDriver(String browser) throws UnCaughtException {
    RunContext context = new RunContext();
    context.BrowserName = browser;
    context.Browser = Browser.fromString(browser);
    context.Platform = Platform.getCurrent();
    context.BrowserVersion = "default";
    launchDriver(context);
}
 
Example 8
Source File: CommandLine.java    From selenium with Apache License 2.0 5 votes vote down vote up
/**
 * @return The platform specific env property name which contains the library path.
 */
public static String getLibraryPathPropertyName() {
  Platform current = Platform.getCurrent();

  if (current.is(WINDOWS)) {
    return "PATH";

  } else if (current.is(MAC)) {
    return "DYLD_LIBRARY_PATH";

  } else {
    return "LD_LIBRARY_PATH";
  }
}
 
Example 9
Source File: InternetExplorerDriver.java    From selenium with Apache License 2.0 5 votes vote down vote up
protected void assertOnWindows() {
  Platform current = Platform.getCurrent();
  if (!current.is(Platform.WINDOWS)) {
    throw new WebDriverException(
        String.format(
            "You appear to be running %s. The IE driver only runs on Windows.", current));
  }
}
 
Example 10
Source File: DriverFactoryTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Test
public void testShouldReturnMatchIfOneFieldMatchesAndOnlyOneDriverIsRegistered() {
  Capabilities template = new DesiredCapabilities("foo", "1.0", Platform.getCurrent());
  DriverProvider provider = mockDriverProviderFor(template);

  factory.registerDriverProvider(provider);

  Capabilities example = new ImmutableCapabilities(BROWSER_NAME, template.getBrowserName());
  assertEquals(provider, factory.getProviderMatching(example));
}
 
Example 11
Source File: JavaDriverTest.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public void supportsJavascriptEnabledCapability() throws Throwable {
    DesiredCapabilities caps = new DesiredCapabilities("java", "1.0", Platform.getCurrent());
    caps.setJavascriptEnabled(true);
    driver = new JavaDriver(caps, caps);
}
 
Example 12
Source File: SeleniumDriver.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 4 votes vote down vote up
public String getPlatformName() {
    Platform platform = null;
    String mode = Control.exe.getExecSettings().getRunSettings().getExecutionMode();
    boolean isLocal = mode.equalsIgnoreCase("Local");
    if (runContext.Platform.equals(Platform.ANY) || runContext.Platform.equals(Platform.getCurrent())) {
        Capabilities cap;
        if (driver instanceof ExtendedHtmlUnitDriver) {
            cap = ((ExtendedHtmlUnitDriver) driver).getCapabilities();
        } else if (driver instanceof MobileDriver) {
            cap = ((RemoteWebDriver) driver).getCapabilities();
            Object platf = cap.getCapability("platformName");
            if (platf != null && !platf.toString().isEmpty()) {
                return platf.toString();
            } else {
                return (driver instanceof AndroidDriver) ? "Android" : "IOS";
            }
        } else if (driver instanceof EmptyDriver) {
            return Platform.getCurrent().name();
        } else {
            cap = ((RemoteWebDriver) driver).getCapabilities();
        }
        platform = cap.getPlatform();
        if (isLocal) {
            platform = Platform.getCurrent();
        }
        if (platform.name().equals(Platform.VISTA.name()) || platform.name().equals(Platform.XP.name())
                || platform.name().equals(Platform.WINDOWS.name()) || platform.name().equals(Platform.WIN8.name())) {
            switch (platform.getMajorVersion() + "." + platform.getMinorVersion()) {
                case "5.1":
                    return "XP";
                case "6.0":
                    return "VISTA";
                case "6.1":
                    return "WIN7";
                case "6.2":
                    return "WIN8";
                case "6.3":
                    return "WIN8.1";
                default:
                    return platform.name();
            }
        } else {
            return platform.toString();
        }
    } else if (runContext.PlatformValue.equals("WINDOWS")) {
        return "WIN";
    } else {
        if (isLocal) {
            platform = Platform.getCurrent();
            return platform.toString();
        }
        return runContext.PlatformValue;
    }
}
 
Example 13
Source File: TestUtilities.java    From selenium with Apache License 2.0 4 votes vote down vote up
public static Platform getEffectivePlatform() {
  return Platform.getCurrent();
}
 
Example 14
Source File: DriverFactoryTest.java    From selenium with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() {
  factory = new DefaultDriverFactory(Platform.getCurrent());
}