Skip to content

Commit

Permalink
Implementing matching for unknown platform names.
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed Nov 10, 2017
1 parent 39e7e8b commit cb4925b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.common.collect.ImmutableList;

import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.remote.CapabilityType;

import java.util.Arrays;
Expand Down Expand Up @@ -49,15 +50,19 @@ private boolean anything(Object requested) {
class PlatformValidator implements Validator {
@Override
public Boolean apply(Map<String, Object> providedCapabilities, Map<String, Object> requestedCapabilities) {
if (anything(requestedCapabilities.get(CapabilityType.PLATFORM))) {
Object requested = requestedCapabilities.get(CapabilityType.PLATFORM);
if (anything(requested)) {
return true;
}
Platform requested = extractPlatform(requestedCapabilities.get(CapabilityType.PLATFORM));
if (requested != null) {
Platform provided = extractPlatform(providedCapabilities.get(CapabilityType.PLATFORM));
return provided != null && provided.is(requested);
Object provided = providedCapabilities.get(CapabilityType.PLATFORM);

Platform requestedPlatform = extractPlatform(requested);
if (requestedPlatform != null) {
Platform providedPlatform = extractPlatform(provided);
return providedPlatform != null && providedPlatform.is(requestedPlatform);
}
return false;

return provided != null && Objects.equals(requested.toString(), provided.toString());
}
}

Expand Down Expand Up @@ -117,9 +122,10 @@ private Platform extractPlatform(Object o) {
if (o instanceof Platform) {
return (Platform) o;
}
if (o instanceof String) {
try {
return Platform.fromString(o.toString());
} catch (WebDriverException ex) {
return null;
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ public void specificPlatformMatchingTest() {
assertFalse(matcher.matches(ImmutableMap.of(CapabilityType.PLATFORM, "linux"), requested));
}

@Test
public void unknownPlatformMatchingTest() {
Map<String, Object> requested = ImmutableMap.of(CapabilityType.PLATFORM, "ms-dos");

assertTrue(matcher.matches(ImmutableMap.of(CapabilityType.PLATFORM, "ms-dos"), requested));

assertFalse(matcher.matches(ImmutableMap.of(CapabilityType.PLATFORM, "windows"), requested));
assertFalse(matcher.matches(ImmutableMap.of(CapabilityType.PLATFORM, "PS/2"), requested));
}

@Test
public void nullEmptyValues() {
Map<String, Object> requested = new HashMap<>();
Expand Down

0 comments on commit cb4925b

Please sign in to comment.