Skip to content

Commit

Permalink
[java] Removing more usages of deprecated "platform" capability.
Browse files Browse the repository at this point in the history
  • Loading branch information
diemol committed May 30, 2022
1 parent c8da7c2 commit 3f794a0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static void setCapability(Map<String, Object> caps, String key, Object value) {
return;
}

if ("platform".equals(key) && value instanceof String) {
if ("platformName".equals(key) && value instanceof String) {
try {
caps.put(key, Platform.fromString((String) value));
} catch (WebDriverException e) {
Expand Down
36 changes: 18 additions & 18 deletions java/test/org/openqa/selenium/remote/DesiredCapabilitiesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,34 +51,34 @@ public void testAddingTheSameCapabilityToAMapTwiceShouldResultInOneEntry() {
@Test
public void testAugmentingCapabilitiesReturnsNewCapabilities() {
DesiredCapabilities origCapabilities = new DesiredCapabilities();
origCapabilities.setCapability("Browser", "firefox");
origCapabilities.setCapability("BrowserName", "firefox");

DesiredCapabilities extraCapabilities = new DesiredCapabilities();
extraCapabilities.setCapability("Platform", "any");
extraCapabilities.setCapability("PlatformName", "any");

origCapabilities.merge(extraCapabilities);
assertThat(origCapabilities.getCapability("Browser")).isEqualTo("firefox");
assertThat(origCapabilities.getCapability("Platform")).isEqualTo("any");
assertThat(origCapabilities.getCapability("BrowserName")).isEqualTo("firefox");
assertThat(origCapabilities.getCapability("PlatformName")).isEqualTo("any");
}

@Test
public void testCopyConstructorWithNullArgument() {
DesiredCapabilities origCapabilities = new DesiredCapabilities((Capabilities) null);

origCapabilities.setCapability("Browser", "firefox");
assertThat(origCapabilities.getCapability("Browser")).isEqualTo("firefox");
origCapabilities.setCapability("BrowserName", "firefox");
assertThat(origCapabilities.getCapability("BrowserName")).isEqualTo("firefox");
}

@Test
public void testCopyConstructorDoesNotAliasToArgument() {
DesiredCapabilities origCapabilities = new DesiredCapabilities();
origCapabilities.setCapability("Browser", "firefox");
origCapabilities.setCapability("BrowserName", "firefox");

DesiredCapabilities newCapabilities = new DesiredCapabilities(origCapabilities);
origCapabilities.setCapability("Browser", "ie");
origCapabilities.setCapability("BrowserName", "ie");

assertThat(origCapabilities.getCapability("Browser")).isEqualTo("ie");
assertThat(newCapabilities.getCapability("Browser")).isEqualTo("firefox");
assertThat(origCapabilities.getCapability("BrowserName")).isEqualTo("ie");
assertThat(newCapabilities.getCapability("BrowserName")).isEqualTo("firefox");
}

@Test
Expand All @@ -95,25 +95,25 @@ public void testExtractDebugLogLevelFromCapabilityMap() {
@Test
public void shouldAutomaticallyConvertPlatformFromStringToEnum() {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(CapabilityType.PLATFORM, "windows 7");
assertThat(caps.getCapability(CapabilityType.PLATFORM)).isEqualTo(Platform.VISTA);
caps.setCapability(CapabilityType.PLATFORM, "win8.1");
assertThat(caps.getCapability(CapabilityType.PLATFORM)).isEqualTo(Platform.WIN8_1);
caps.setCapability(CapabilityType.PLATFORM_NAME, "windows 7");
assertThat(caps.getCapability(CapabilityType.PLATFORM_NAME)).isEqualTo(Platform.VISTA);
caps.setCapability(CapabilityType.PLATFORM_NAME, "win8.1");
assertThat(caps.getCapability(CapabilityType.PLATFORM_NAME)).isEqualTo(Platform.WIN8_1);
}

@Test
public void shouldNotAutomaticallyConvertPlatformIfItNotConvertible() {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(CapabilityType.PLATFORM, "FreeBSD");
assertThat(caps.getCapability(CapabilityType.PLATFORM)).isEqualTo("FreeBSD");
caps.setCapability(CapabilityType.PLATFORM_NAME, "FreeBSD");
assertThat(caps.getCapability(CapabilityType.PLATFORM_NAME)).isEqualTo("FreeBSD");
}

@Test
public void shouldNotAutomaticallyConvertPlatformIfItNotConvertibleInConstructor() {
Map<String, Object> capabilitiesMap = ImmutableMap.of(CapabilityType.PLATFORM, "FreeBSD");
Map<String, Object> capabilitiesMap = ImmutableMap.of(CapabilityType.PLATFORM_NAME, "FreeBSD");

DesiredCapabilities caps = new DesiredCapabilities(capabilitiesMap);
assertThat(caps.getCapability(CapabilityType.PLATFORM)).isEqualTo("FreeBSD");
assertThat(caps.getCapability(CapabilityType.PLATFORM_NAME)).isEqualTo("FreeBSD");
}

@Test
Expand Down
35 changes: 16 additions & 19 deletions java/test/org/openqa/selenium/remote/NewSessionPayloadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,6 @@

package org.openqa.selenium.remote;

import static java.util.Arrays.asList;
import static java.util.Collections.EMPTY_MAP;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singleton;
import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static java.util.stream.Collectors.toList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.openqa.selenium.json.Json.MAP_TYPE;

import com.google.common.collect.ImmutableMap;

import org.junit.Test;
Expand All @@ -46,6 +33,19 @@
import java.util.List;
import java.util.Map;

import static java.util.Arrays.asList;
import static java.util.Collections.EMPTY_MAP;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singleton;
import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static java.util.stream.Collectors.toList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.openqa.selenium.json.Json.MAP_TYPE;

@Category(UnitTests.class)
public class NewSessionPayloadTest {

Expand Down Expand Up @@ -165,12 +165,11 @@ public void shouldMergeAlwaysAndFirstMatches() {
@Test
public void shouldCorrectlyExtractPlatformNameFromOssCapabilities() {
List<Capabilities> capabilities = create(singletonMap(
"desiredCapabilities", singletonMap(
"platform", "linux")));
"desiredCapabilities", singletonMap(
"platformName", "linux")));

assertEquals(Platform.LINUX, capabilities.get(0).getPlatformName());
assertEquals(Platform.LINUX, capabilities.get(0).getCapability("platform"));
assertNull(capabilities.get(0).getCapability("platformName"));
assertEquals(Platform.LINUX, capabilities.get(0).getCapability("platformName"));
}

@Test
Expand All @@ -181,8 +180,6 @@ public void shouldCorrectlyExtractPlatformFromW3cCapabilities() {
"platformName", "linux"))));

assertEquals(Platform.LINUX, capabilities.get(0).getPlatformName());
assertNull(capabilities.get(0).getCapability("platform"));
assertEquals("linux", capabilities.get(0).getCapability("platformName"));
}

@Test
Expand Down

0 comments on commit 3f794a0

Please sign in to comment.