Skip to content

Commit

Permalink
Fixing platform autocoversion. Fixes issue 8083
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed Oct 27, 2014
1 parent f36cb1b commit 396f255
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 17 additions & 0 deletions java/client/src/org/openqa/selenium/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,23 @@ public static Platform extractFromSysProperty(String osName, String osVersion) {
return mostLikely;
}

/**
* Gets a platform with the name matching the parameter.
*
* @param name the platform name
* @return the Platform enum value matching the parameter
*/
public static Platform fromString(String name) {
for (Platform os : Platform.values()) {
for (String matcher : os.partOfOsName) {
if (name.toLowerCase().equals(matcher.toLowerCase())) {
return os;
}
}
}
throw new WebDriverException("Unknown platform: " + name);
}

/**
* Decides whether the previous match is better or not than the current match. If previous match
* is null, the newer match is always better.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public void setCapability(String capabilityName, boolean value) {

public void setCapability(String capabilityName, String value) {
if (PLATFORM.equals(capabilityName)) {
capabilities.put(capabilityName, Platform.valueOf(value));
capabilities.put(capabilityName, Platform.fromString(value));
} else {
capabilities.put(capabilityName, value);
}
Expand All @@ -177,7 +177,7 @@ public void setCapability(String capabilityName, Platform value) {

public void setCapability(String key, Object value) {
if (PLATFORM.equals(key) && value instanceof String) {
capabilities.put(key, Platform.valueOf((String) value));
capabilities.put(key, Platform.fromString((String) value));
} else {
capabilities.put(key, value);
}
Expand Down

0 comments on commit 396f255

Please sign in to comment.