下面列出了怎么用org.openqa.selenium.Platform的API类实例代码及写法,或者点击链接到github查看源代码。
private static boolean isPlatformName(Capabilities capabilities, String platformName)
{
return checkCapabilities(capabilities, () ->
{
Object platformNameFromCaps = capabilities.getCapability(CapabilityType.PLATFORM_NAME);
if (platformNameFromCaps instanceof String)
{
return platformNameFromCaps.equals(platformName);
}
if (platformNameFromCaps instanceof Platform)
{
return platformNameFromCaps == Platform.fromString(platformName);
}
return false;
});
}
/**
* 通常のフォーマットテスト(セレクタ)
*/
@Test
public void testFormat_selector() throws Exception {
PtlCapabilities capabilities = new PtlCapabilities(new HashMap<String, Object>());
capabilities.setPlatform(Platform.WINDOWS);
capabilities.setBrowserName("firefox");
capabilities.setVersion("38");
PersistMetadata metadata = new PersistMetadata("testId", "testClass", "testMethod", "scId",
new IndexDomSelector(SelectorType.TAG_NAME, "body", 1), null, capabilities);
FileNameFormatter formatter = new FileNameFormatter(
"{platformName}_{platformVersion}_{browserName}_{version}_{screenArea}.png");
String result = formatter.format(metadata);
assertThat(result, is("testMethod_scId_WINDOWS_firefox_38_TAG_NAME_body_[1].png"));
}
protected static RemoteWebDriver createSauce ( final Platform os, final String browser, final String version ) throws MalformedURLException
{
final DesiredCapabilities capabilities = new DesiredCapabilities ();
capabilities.setBrowserName ( browser );
if ( version != null )
{
capabilities.setVersion ( version );
}
capabilities.setCapability ( CapabilityType.PLATFORM, os );
capabilities.setCapability ( CapabilityType.SUPPORTS_FINDING_BY_CSS, true );
capabilities.setCapability ( "name", "Eclipse Package Drone Main Test" );
if ( System.getenv ( "TRAVIS_JOB_NUMBER" ) != null )
{
capabilities.setCapability ( "tunnel-identifier", System.getenv ( "TRAVIS_JOB_NUMBER" ) );
capabilities.setCapability ( "build", System.getenv ( "TRAVIS_BUILD_NUMBER" ) );
capabilities.setCapability ( "tags", new String[] { "CI" } );
}
final RemoteWebDriver driver = new RemoteWebDriver ( new URL ( String.format ( "http://%s:%[email protected]%s/wd/hub", SAUCE_USER_NAME, SAUCE_ACCESS_KEY, SAUCE_URL ) ), capabilities );
driver.setFileDetector ( new LocalFileDetector () );
return driver;
}
@Test
public void shouldPickCorrectBrowser() {
Capabilities chrome = new DesiredCapabilities(BrowserType.CHROME, "10", Platform.ANY);
Capabilities firefox = new DesiredCapabilities(BrowserType.FIREFOX, "10", Platform.ANY);
Capabilities opera = new DesiredCapabilities(BrowserType.OPERA_BLINK, "10", Platform.ANY);
List<Capabilities> list = asList(chrome, firefox, opera);
DesiredCapabilities desired = new DesiredCapabilities();
desired.setBrowserName(BrowserType.CHROME);
assertThat(getBestMatch(desired, list)).isEqualTo(chrome);
desired.setBrowserName(BrowserType.FIREFOX);
assertThat(getBestMatch(desired, list)).isEqualTo(firefox);
desired.setBrowserName(BrowserType.OPERA_BLINK);
assertThat(getBestMatch(desired, list)).isEqualTo(opera);
}
/**
* {@link Platform#family()}から辿れるPlatformの親一覧を取得します。
*
* @param platform 対象のPlatform
* @return 引数のPlatformと、引数のPlatformの親Platform一覧
*/
private static Collection<Platform> toPlatformFamily(Platform platform) {
Set<Platform> platforms = EnumSet.noneOf(Platform.class);
if (platform == null) {
return platforms;
}
platforms.add(platform);
Platform parent = platform.family();
while (parent != null && parent != Platform.ANY) {
platforms.add(parent);
parent = parent.family();
}
return platforms;
}
@Test
public void shouldConvertAProxyCorrectly() {
Proxy proxy = new Proxy();
proxy.setHttpProxy("localhost:4444");
MutableCapabilities caps = new DesiredCapabilities("foo", "1", Platform.LINUX);
caps.setCapability(CapabilityType.PROXY, proxy);
Map<String, ?> asMap = ImmutableMap.of("desiredCapabilities", caps);
Command command = new Command(new SessionId("empty"), DriverCommand.NEW_SESSION, asMap);
String json = convert(command.getParameters());
JsonObject converted = new JsonParser().parse(json).getAsJsonObject();
JsonObject capsAsMap = converted.get("desiredCapabilities").getAsJsonObject();
assertThat(capsAsMap.get(CapabilityType.PROXY).getAsJsonObject().get("httpProxy").getAsString())
.isEqualTo(proxy.getHttpProxy());
}
@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()));
}
@Test
public void testCleanupDriver() throws Throwable {
final WebDriver webDriver = mock(WebDriver.class);
TestEnvironment env = new TestEnvironment(null, null, Platform.WINDOWS){
@Override
public WebDriver getWebDriver(){
return webDriver;
}
};
assertEquals(webDriver, env.getWebDriver());
env.cleanupDriver();
verify(webDriver, times(1)).quit();
env.cleanupAllDrivers();
}
/**
* 通常のフォーマットテスト(矩形)
*/
@Test
public void testFormat_rectangle() throws Exception {
PtlCapabilities capabilities = new PtlCapabilities(new HashMap<String, Object>());
capabilities.setPlatform(Platform.WINDOWS);
capabilities.setBrowserName("firefox");
capabilities.setVersion("38");
PersistMetadata metadata = new PersistMetadata("testId", "testClass", "testMethod", "scId", null,
new RectangleArea(0, 10, 100, 1000), capabilities);
FileNameFormatter formatter = new FileNameFormatter(
"{platformName}_{platformVersion}_{browserName}_{version}_{screenArea}.png");
String result = formatter.format(metadata);
assertThat(result, is("testMethod_scId_WINDOWS_firefox_38_rect_0_10_100_1000.png"));
}
private InternetExplorerOptions getIEOptions() {
InternetExplorerOptions caps = new InternetExplorerOptions();
caps.setCapability("version", this.version);
caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
caps.setCapability(InternetExplorerDriver.IE_SWITCHES, "-private");
caps.setCapability(InternetExplorerDriver.FORCE_CREATE_PROCESS, true);
caps.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
caps.setCapability(CapabilityType.SUPPORTS_ALERTS, true);
caps.setCapability("platform", Platform.WINDOWS);
caps.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
caps.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, this.alertBehaviour);
//Found that setting this capability could increase IE tests speed. Should be checked.
caps.setCapability(InternetExplorerDriver.REQUIRE_WINDOW_FOCUS, true);
setLoggingPrefs(caps);
return caps;
}
@Test
public void shouldPickUpBinaryFromSystemPropertyIfSet() throws IOException {
JreSystemProperty property = new JreSystemProperty(BROWSER_BINARY);
Path binary = Files.createTempFile("firefox", ".exe");
try (OutputStream ignored = Files.newOutputStream(binary, DELETE_ON_CLOSE)) {
Files.write(binary, "".getBytes());
if (! TestUtilities.getEffectivePlatform().is(Platform.WINDOWS)) {
Files.setPosixFilePermissions(binary, singleton(PosixFilePermission.OWNER_EXECUTE));
}
property.set(binary.toString());
FirefoxOptions options = new FirefoxOptions();
FirefoxBinary firefoxBinary =
options.getBinaryOrNull().orElseThrow(() -> new AssertionError("No binary"));
assertThat(firefoxBinary.getPath()).isEqualTo(binary.toString());
} finally {
property.reset();
}
}
public void failsWhenRequestingNonCurrentPlatform() throws Throwable {
Platform[] values = Platform.values();
Platform otherPlatform = null;
for (Platform platform : values) {
if (Platform.getCurrent().is(platform)) {
continue;
}
otherPlatform = platform;
break;
}
DesiredCapabilities caps = new DesiredCapabilities("java", "1.0", otherPlatform);
try {
driver = new JavaDriver(caps, caps);
throw new MissingException(SessionNotCreatedException.class);
} catch (SessionNotCreatedException e) {
}
}
@Test
public void currentPlatformCheckDoesNotTrumpExactPlatformMatch() {
Capabilities chromeUnix = capabilities(BrowserType.CHROME, "", Platform.UNIX, true);
Capabilities chromeVista = capabilities(BrowserType.CHROME, "", Platform.VISTA, true);
Capabilities anyChrome = new DesiredCapabilities(BrowserType.CHROME, "10", Platform.ANY);
List<Capabilities> allCaps = asList(anyChrome, chromeVista, chromeUnix);
assertThat(getBestMatch(chromeVista, allCaps, Platform.UNIX)).isEqualTo(chromeVista);
assertThat(getBestMatch(chromeVista, allCaps, Platform.LINUX)).isEqualTo(chromeVista);
assertThat(getBestMatch(chromeVista, allCaps, Platform.MAC)).isEqualTo(chromeVista);
assertThat(getBestMatch(chromeUnix, allCaps, Platform.MAC)).isEqualTo(chromeUnix);
assertThat(getBestMatch(chromeUnix, allCaps, Platform.VISTA)).isEqualTo(chromeUnix);
assertThat(getBestMatch(chromeUnix, allCaps, Platform.WINDOWS)).isEqualTo(chromeUnix);
}
@Override
public void fetchConfig() throws IOException {
List<JsonObject> availableConfigList = this.getAvailableConfigList(null, null);
/* might be not necessary, depending on data format it DB */
for (JsonObject jsonObject : availableConfigList) {
Client client = new Client();
client.getBrowserSpecs().setVersion(jsonObject.getString("version", ""));
String browserName = jsonObject.getString("name", "");
if (browserName.endsWith("edge"))
browserName = BrowserType.EDGE;
else if (browserName.equalsIgnoreCase(BrowserType.GOOGLECHROME))
browserName = BrowserType.CHROME;
client.getBrowserSpecs().setBrowserName(browserName);
String platform = jsonObject.getString("platform", "");
client.getBrowserSpecs().setPlatform(
platform.equalsIgnoreCase("CAPITAN") ? Platform.EL_CAPITAN : Platform.fromString(platform));
this.clientList.add(client);
}
}
private void checkTestEnvironment(BrowserConfiguration config)
{
Assert.assertNotNull(config);
Assert.assertEquals("testEnvironmentFlags", config.getConfigTag());
Assert.assertEquals("Test Environment Browser", config.getName());
MutableCapabilities testCapabilities = config.getCapabilities();
Assert.assertEquals("chrome", testCapabilities.getBrowserName());
Assert.assertEquals(1234, testCapabilities.getCapability("idleTimeout"));
Assert.assertEquals(1234, testCapabilities.getCapability("idletimeout"));
Assert.assertEquals(5678, testCapabilities.getCapability("maxDuration"));
Assert.assertEquals(5678, testCapabilities.getCapability("maxduration"));
Assert.assertEquals("3.1234", testCapabilities.getCapability("seleniumVersion"));
Assert.assertEquals("3.1234", testCapabilities.getCapability("selenium-version"));
Assert.assertEquals("800x600", testCapabilities.getCapability("screenResolution"));
Assert.assertEquals("800x600", testCapabilities.getCapability("screen-resolution"));
Assert.assertEquals(Platform.VISTA, testCapabilities.getCapability("platform"));
Assert.assertEquals("Windows 10", testCapabilities.getCapability("platformName"));
Assert.assertEquals("MyDevice", testCapabilities.getCapability("deviceName"));
Assert.assertEquals("portrait", testCapabilities.getCapability("deviceOrientation"));
Assert.assertEquals("landscape", testCapabilities.getCapability("orientation"));
}
@Test
public void shouldCorrectlyExtractPlatformFromW3cCapabilities() {
List<Capabilities> capabilities = create(singletonMap(
"capabilities", singletonMap(
"alwaysMatch", singletonMap(
"platformName", "linux"))));
assertEquals(Platform.LINUX, capabilities.get(0).getPlatform());
assertNull(capabilities.get(0).getCapability("platform"));
assertEquals("linux", capabilities.get(0).getCapability("platformName"));
}
@Test
public void testShouldRegisterCorrectDefaultsOnMac() {
DefaultDriverFactory factory = new DefaultDriverFactory(Platform.MAC);
assertTrue(canInstantiate(factory, CHROME));
assertTrue(canInstantiate(factory, EDGE));
assertTrue(canInstantiate(factory, FIREFOX));
assertTrue(canInstantiate(factory, SAFARI));
assertFalse(canInstantiate(factory, IE));
}
@Override
public int score(Platform value) {
if (!currentIsDesired || isNullOrAny(value)) {
return 0;
}
return scoreAgainst.is(value) || value.is(scoreAgainst) ? 1 : -1;
}
@Test
@Ignore(IE)
@NotYetImplemented(value = MARIONETTE, reason = "https://bugzilla.mozilla.org/show_bug.cgi?id=1422583")
@NotYetImplemented(CHROME)
public void testSelectionSelectByWord() {
assumeFalse(
"MacOS has alternative keyboard",
getEffectivePlatform(driver).is(Platform.MAC));
driver.get(appServer.whereIs("single_text_input.html"));
WebElement input = driver.findElement(By.id("textInput"));
getBuilder(driver).click(input).sendKeys("abc def").perform();
wait.until(ExpectedConditions.attributeToBe(input, "value", "abc def"));
getBuilder(driver).click(input)
.keyDown(Keys.SHIFT)
.keyDown(Keys.CONTROL)
.sendKeys(Keys.LEFT)
.keyUp(Keys.CONTROL)
.keyUp(Keys.SHIFT)
.sendKeys(Keys.DELETE)
.perform();
wait.until(ExpectedConditions.attributeToBe(input, "value", "abc "));
}
private void instantiateWebDriver(DriverType driverType) throws MalformedURLException {
System.out.println(" ");
System.out.println("Local Operating System: " + operatingSystem);
System.out.println("Local Architecture: " + systemArchitecture);
System.out.println("Selected Browser: " + selectedDriverType);
System.out.println("Connecting to Selenium Grid: " + useRemoteWebDriver);
System.out.println(" ");
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
if (useRemoteWebDriver) {
URL seleniumGridURL = new URL(System.getProperty("gridURL"));
String desiredBrowserVersion = System.getProperty("desiredBrowserVersion");
String desiredPlatform = System.getProperty("desiredPlatform");
if (null != desiredPlatform && !desiredPlatform.isEmpty()) {
desiredCapabilities.setPlatform(Platform.valueOf(desiredPlatform.toUpperCase()));
}
if (null != desiredBrowserVersion && !desiredBrowserVersion.isEmpty()) {
desiredCapabilities.setVersion(desiredBrowserVersion);
}
desiredCapabilities.setBrowserName(selectedDriverType.toString());
webDriver = new RemoteWebDriver(seleniumGridURL, desiredCapabilities);
} else {
webDriver = driverType.getWebDriverObject(desiredCapabilities);
}
}
private void instantiateWebDriver(DriverType driverType) throws MalformedURLException {
System.out.println(" ");
System.out.println("Local Operating System: " + operatingSystem);
System.out.println("Local Architecture: " + systemArchitecture);
System.out.println("Selected Browser: " + selectedDriverType);
System.out.println("Connecting to Selenium Grid: " + useRemoteWebDriver);
System.out.println(" ");
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
if (useRemoteWebDriver) {
URL seleniumGridURL = new URL(System.getProperty("gridURL"));
String desiredBrowserVersion = System.getProperty("desiredBrowserVersion");
String desiredPlatform = System.getProperty("desiredPlatform");
if (null != desiredPlatform && !desiredPlatform.isEmpty()) {
desiredCapabilities.setPlatform(Platform.valueOf(desiredPlatform.toUpperCase()));
}
if (null != desiredBrowserVersion && !desiredBrowserVersion.isEmpty()) {
desiredCapabilities.setVersion(desiredBrowserVersion);
}
desiredCapabilities.setBrowserName(selectedDriverType.toString());
webDriver = new RemoteWebDriver(seleniumGridURL, desiredCapabilities);
} else {
webDriver = driverType.getWebDriverObject(desiredCapabilities);
}
}
private void instantiateWebDriver(DriverType driverType) throws MalformedURLException {
System.out.println(" ");
System.out.println("Local Operating System: " + operatingSystem);
System.out.println("Local Architecture: " + systemArchitecture);
System.out.println("Selected Browser: " + selectedDriverType);
System.out.println("Connecting to Selenium Grid: " + useRemoteWebDriver);
System.out.println(" ");
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
if (useRemoteWebDriver) {
URL seleniumGridURL = new URL(System.getProperty("gridURL"));
String desiredBrowserVersion = System.getProperty("desiredBrowserVersion");
String desiredPlatform = System.getProperty("desiredPlatform");
if (null != desiredPlatform && !desiredPlatform.isEmpty()) {
desiredCapabilities.setPlatform(Platform.valueOf(desiredPlatform.toUpperCase()));
}
if (null != desiredBrowserVersion && !desiredBrowserVersion.isEmpty()) {
desiredCapabilities.setVersion(desiredBrowserVersion);
}
desiredCapabilities.setBrowserName(selectedDriverType.toString());
webDriver = new RemoteWebDriver(seleniumGridURL, desiredCapabilities);
} else {
webDriver = driverType.getWebDriverObject(desiredCapabilities);
}
}
private void instantiateWebDriver(AppiumDriverType appiumDriverType) throws MalformedURLException {
System.out.println("Current Appium Config Selection: " + selectedDriverConfiguration);
System.out.println("Current Appium Server Location: " + APPIUM_SERVER_LOCATION);
System.out.println("Connecting to Selenium Grid: " + USE_SELENIUM_GRID);
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
if (Boolean.getBoolean("enableDebugMode")) {
desiredCapabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, "3600");
}
Optional.ofNullable(System.getProperty("device_id", null))
.ifPresent(deviceID -> desiredCapabilities.setCapability(MobileCapabilityType.UDID, deviceID));
if (USE_SELENIUM_GRID) {
URL seleniumGridURL = new URL(System.getProperty("gridURL"));
String desiredVersion = System.getProperty("desiredVersion");
String desiredPlatform = System.getProperty("desiredPlatform");
if (null != desiredPlatform && !desiredPlatform.isEmpty()) {
desiredCapabilities.setPlatform(Platform.valueOf(desiredPlatform.toUpperCase()));
}
if (null != desiredVersion && !desiredVersion.isEmpty()) {
desiredCapabilities.setVersion(desiredVersion);
}
desiredCapabilities.setBrowserName(selectedDriverConfiguration.toString());
driver = new AppiumDriver(seleniumGridURL, desiredCapabilities);
} else {
driver = appiumDriverType.createAppiumObject(new URL(APPIUM_SERVER_LOCATION), desiredCapabilities)
.setActivity(currentActivity)
.getAppiumDriver();
}
}
private void instantiateWebDriver(DriverType driverType) throws MalformedURLException {
System.out.println(" ");
System.out.println("Local Operating System: " + operatingSystem);
System.out.println("Local Architecture: " + systemArchitecture);
System.out.println("Selected Browser: " + selectedDriverType);
System.out.println("Connecting to Selenium Grid: " + useRemoteWebDriver);
System.out.println(" ");
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
if (useRemoteWebDriver) {
URL seleniumGridURL = new URL(System.getProperty("gridURL"));
String desiredBrowserVersion = System.getProperty("desiredBrowserVersion");
String desiredPlatform = System.getProperty("desiredPlatform");
if (null != desiredPlatform && !desiredPlatform.isEmpty()) {
desiredCapabilities.setPlatform(Platform.valueOf(desiredPlatform.toUpperCase()));
}
if (null != desiredBrowserVersion && !desiredBrowserVersion.isEmpty()) {
desiredCapabilities.setVersion(desiredBrowserVersion);
}
desiredCapabilities.setBrowserName(selectedDriverType.toString());
webDriver = new RemoteWebDriver(seleniumGridURL, desiredCapabilities);
} else {
webDriver = driverType.getWebDriverObject(desiredCapabilities);
}
}
/**
* プラットフォーム名を取得します。
*
* @return プラットフォーム名
*/
public String getPlatformName() {
Platform platform = getPlatform();
if (platform != null) {
return platform.name();
} else {
return toString(getCapability("platformName"));
}
}
/**
* Returns a single address that is guaranteed to resolve to an ipv4 representation of localhost
* This may either be a hostname or an ip address, depending if we can guarantee what that the
* hostname will resolve to ip4.
*
* @return The address part og such an address
*/
public String obtainLoopbackIp4Address() {
final NetworkInterface networkInterface = getLoopBackAndIp4Only();
if (networkInterface != null) {
return networkInterface.getIp4LoopbackOnly().getHostName();
}
final String ipOfIp4LoopBack = getIpOfLoopBackIp4();
if (ipOfIp4LoopBack != null) {
return ipOfIp4LoopBack;
}
if (Platform.getCurrent().is(Platform.UNIX)) {
NetworkInterface linuxLoopback = networkInterfaceProvider.getLoInterface();
if (linuxLoopback != null) {
final InetAddress netAddress = linuxLoopback.getIp4LoopbackOnly();
if (netAddress != null) {
return netAddress.getHostAddress();
}
}
}
throw new WebDriverException(
"Unable to resolve local loopback address, please file an issue with the full message of this error:\n"
+
getNetWorkDiags() + "\n==== End of error message");
}
private void instantiateWebDriver(DriverType driverType) throws MalformedURLException {
System.out.println(" ");
System.out.println("Local Operating System: " + operatingSystem);
System.out.println("Local Architecture: " + systemArchitecture);
System.out.println("Selected Browser: " + selectedDriverType);
System.out.println("Connecting to Selenium Grid: " + useRemoteWebDriver);
System.out.println(" ");
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
if (useRemoteWebDriver) {
URL seleniumGridURL = new URL(System.getProperty("gridURL"));
String desiredBrowserVersion = System.getProperty("desiredBrowserVersion");
String desiredPlatform = System.getProperty("desiredPlatform");
if (null != desiredPlatform && !desiredPlatform.isEmpty()) {
desiredCapabilities.setPlatform(Platform.valueOf(desiredPlatform.toUpperCase()));
}
if (null != desiredBrowserVersion && !desiredBrowserVersion.isEmpty()) {
desiredCapabilities.setVersion(desiredBrowserVersion);
}
desiredCapabilities.setBrowserName(selectedDriverType.toString());
webDriver = new RemoteWebDriver(seleniumGridURL, desiredCapabilities);
} else {
webDriver = driverType.getWebDriverObject(desiredCapabilities);
}
}
private void instantiateWebDriver(DriverType driverType) throws MalformedURLException {
System.out.println(" ");
System.out.println("Local Operating System: " + operatingSystem);
System.out.println("Local Architecture: " + systemArchitecture);
System.out.println("Selected Browser: " + selectedDriverType);
System.out.println("Connecting to Selenium Grid: " + useRemoteWebDriver);
System.out.println(" ");
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
if (useRemoteWebDriver) {
URL seleniumGridURL = new URL(System.getProperty("gridURL"));
String desiredBrowserVersion = System.getProperty("desiredBrowserVersion");
String desiredPlatform = System.getProperty("desiredPlatform");
if (null != desiredPlatform && !desiredPlatform.isEmpty()) {
desiredCapabilities.setPlatform(Platform.valueOf(desiredPlatform.toUpperCase()));
}
if (null != desiredBrowserVersion && !desiredBrowserVersion.isEmpty()) {
desiredCapabilities.setVersion(desiredBrowserVersion);
}
desiredCapabilities.setBrowserName(selectedDriverType.toString());
webDriver = new RemoteWebDriver(seleniumGridURL, desiredCapabilities);
} else {
webDriver = driverType.getWebDriverObject(desiredCapabilities);
}
}
@Test
public void canHandlePlatformOSSCapability() throws IOException {
CommandExecutor executor = prepareExecutorMock(echoCapabilities, nullResponder);
ImmutableCapabilities capabilities = new ImmutableCapabilities(
"browserName", "cheese browser", "platform", Platform.MOJAVE);
RemoteWebDriver driver = new RemoteWebDriver(executor, capabilities);
assertThat(driver.getCapabilities().getPlatform().is(Platform.MOJAVE)).isTrue();
}
@Override
public boolean isAndroid(@NotNull final WebDriver webDriver) {
final Capabilities remoteWebDriverCapabilities = ((RemoteWebDriver) webDriver).getCapabilities();
return remoteWebDriverCapabilities.getPlatform().is(Platform.ANDROID)
// realMobile and Linux means a remote browserstack android device
|| (remoteWebDriverCapabilities.getPlatform().is(Platform.LINUX)
&& "true".equals(remoteWebDriverCapabilities.asMap().get("realMobile")));
}