Skip to content

Commit 06bf213

Browse files
committed
Normalise handling of Platform in ImmutableCapabilities
1 parent 49f7c1a commit 06bf213

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

java/client/src/org/openqa/selenium/Capabilities.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ default Platform getPlatform() {
4343
}
4444

4545
if (rawPlatform instanceof String) {
46-
return Platform.valueOf((String) rawPlatform);
46+
return Platform.fromString((String) rawPlatform);
4747
} else if (rawPlatform instanceof Platform) {
4848
return (Platform) rawPlatform;
4949
}

java/client/src/org/openqa/selenium/ImmutableCapabilities.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,27 @@ public ImmutableCapabilities(Map<String, ?> capabilities) {
4242
caps.put(key, value);
4343
}
4444
});
45+
46+
// Normalise the "platform" value for both OSS and W3C.
47+
Object value = caps.getOrDefault("platform", caps.get("platformName"));
48+
if (value != null) {
49+
Object platform;
50+
if (value instanceof Platform) {
51+
platform = (Platform) value;
52+
} else if (value instanceof String) {
53+
try {
54+
platform = Platform.fromString((String) value);
55+
} catch (WebDriverException ignored) {
56+
// Just use the string we were given.
57+
platform = value;
58+
}
59+
} else {
60+
throw new IllegalStateException("Platform was neither a string or a Platform: " + value);
61+
}
62+
63+
caps.put("platform", platform);
64+
caps.put("platformName", platform);
65+
}
4566
}
4667

4768
@Override

java/client/src/org/openqa/selenium/Platform.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public String toString() {
124124
return "OS X 10.10";
125125
}
126126
},
127-
127+
128128
EL_CAPITAN("el capitan", "os x 10.11") {
129129
@Override
130130
public Platform family() {
@@ -284,18 +284,20 @@ public static Platform extractFromSysProperty(String osName, String osVersion) {
284284
* @return the Platform enum value matching the parameter
285285
*/
286286
public static Platform fromString(String name) {
287-
try {
288-
return Platform.valueOf(name);
289-
} catch (IllegalArgumentException ex) {
290-
for (Platform os : Platform.values()) {
291-
for (String matcher : os.partOfOsName) {
292-
if (name.toLowerCase().equals(matcher.toLowerCase())) {
293-
return os;
294-
}
287+
for (Platform platform : values()) {
288+
if (platform.toString().equalsIgnoreCase(name)) {
289+
return platform;
290+
}
291+
}
292+
293+
for (Platform os : Platform.values()) {
294+
for (String matcher : os.partOfOsName) {
295+
if (name.toLowerCase().equals(matcher.toLowerCase())) {
296+
return os;
295297
}
296298
}
297-
throw new WebDriverException("Unrecognized platform: " + name);
298299
}
300+
throw new WebDriverException("Unrecognized platform: " + name);
299301
}
300302

301303
/**

0 commit comments

Comments
 (0)