下面列出了org.openqa.selenium.Platform#getCurrent ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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());
}
@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()));
}
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) {
}
}
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) {
}
}
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"));
}
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"));
}
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);
}
/**
* @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";
}
}
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));
}
}
@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));
}
public void supportsJavascriptEnabledCapability() throws Throwable {
DesiredCapabilities caps = new DesiredCapabilities("java", "1.0", Platform.getCurrent());
caps.setJavascriptEnabled(true);
driver = new JavaDriver(caps, caps);
}
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;
}
}
public static Platform getEffectivePlatform() {
return Platform.getCurrent();
}
@Before
public void setUp() {
factory = new DefaultDriverFactory(Platform.getCurrent());
}