diff --git a/java/client/src/org/openqa/selenium/Platform.java b/java/client/src/org/openqa/selenium/Platform.java index 5e27bc6abfeed..9fd7b8d6058f8 100644 --- a/java/client/src/org/openqa/selenium/Platform.java +++ b/java/client/src/org/openqa/selenium/Platform.java @@ -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. diff --git a/java/client/src/org/openqa/selenium/remote/DesiredCapabilities.java b/java/client/src/org/openqa/selenium/remote/DesiredCapabilities.java index 6746cde2e7663..54c157bdd8a27 100644 --- a/java/client/src/org/openqa/selenium/remote/DesiredCapabilities.java +++ b/java/client/src/org/openqa/selenium/remote/DesiredCapabilities.java @@ -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); } @@ -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); }