Skip to content

Commit 396f255

Browse files
committed
Fixing platform autocoversion. Fixes issue 8083
1 parent f36cb1b commit 396f255

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

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

+17
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,23 @@ public static Platform extractFromSysProperty(String osName, String osVersion) {
203203
return mostLikely;
204204
}
205205

206+
/**
207+
* Gets a platform with the name matching the parameter.
208+
*
209+
* @param name the platform name
210+
* @return the Platform enum value matching the parameter
211+
*/
212+
public static Platform fromString(String name) {
213+
for (Platform os : Platform.values()) {
214+
for (String matcher : os.partOfOsName) {
215+
if (name.toLowerCase().equals(matcher.toLowerCase())) {
216+
return os;
217+
}
218+
}
219+
}
220+
throw new WebDriverException("Unknown platform: " + name);
221+
}
222+
206223
/**
207224
* Decides whether the previous match is better or not than the current match. If previous match
208225
* is null, the newer match is always better.

java/client/src/org/openqa/selenium/remote/DesiredCapabilities.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public void setCapability(String capabilityName, boolean value) {
165165

166166
public void setCapability(String capabilityName, String value) {
167167
if (PLATFORM.equals(capabilityName)) {
168-
capabilities.put(capabilityName, Platform.valueOf(value));
168+
capabilities.put(capabilityName, Platform.fromString(value));
169169
} else {
170170
capabilities.put(capabilityName, value);
171171
}
@@ -177,7 +177,7 @@ public void setCapability(String capabilityName, Platform value) {
177177

178178
public void setCapability(String key, Object value) {
179179
if (PLATFORM.equals(key) && value instanceof String) {
180-
capabilities.put(key, Platform.valueOf((String) value));
180+
capabilities.put(key, Platform.fromString((String) value));
181181
} else {
182182
capabilities.put(key, value);
183183
}

0 commit comments

Comments
 (0)