Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions java/src/org/openqa/selenium/grid/data/DefaultSlotMatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class DefaultSlotMatcher implements SlotMatcher, Serializable {
*/
private static final List<String> EXTENSION_CAPABILITIES_PREFIXES =
Arrays.asList("goog:", "moz:", "ms:", "se:");
private static final String SLOT_MATCHER_PREFIX = "se:slotMatcher";

@Override
public boolean matches(Capabilities stereotype, Capabilities capabilities) {
Expand All @@ -74,6 +75,10 @@ public boolean matches(Capabilities stereotype, Capabilities capabilities) {
return false;
}

if (!extensionCapabilitiesMatch(stereotype, capabilities, SLOT_MATCHER_PREFIX, false)) {
return false;
}

// At the end, a simple browser, browserVersion and platformName match
boolean browserNameMatch =
(capabilities.getBrowserName() == null || capabilities.getBrowserName().isEmpty())
Expand Down Expand Up @@ -150,10 +155,21 @@ private Boolean extensionCapabilitiesMatch(Capabilities stereotype, Capabilities
EXTENSION_CAPABILITIES_PREFIXES items. Also, we match them only when the capabilities
of the new session request contains that specific extension capability.
*/
return extensionCapabilitiesMatch(stereotype, capabilities, ":", true);
}

private Boolean extensionCapabilitiesMatch(
Capabilities stereotype,
Capabilities capabilities,
String nameContains,
boolean excludeExtensionPrefixes) {
return stereotype.getCapabilityNames().stream()
.filter(name -> name.contains(":"))
.filter(name -> name.contains(nameContains))
.filter(name -> capabilities.asMap().containsKey(name))
.filter(name -> EXTENSION_CAPABILITIES_PREFIXES.stream().noneMatch(name::contains))
.filter(
name ->
!excludeExtensionPrefixes
|| EXTENSION_CAPABILITIES_PREFIXES.stream().noneMatch(name::contains))
.map(
name -> {
if (capabilities.getCapability(name) instanceof String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,35 @@ void prefixedPlatformVersionDoesNotMatch() {
assertThat(slotMatcher.matches(stereotype, capabilities)).isFalse();
}

@Test
void prefixedSlotMatcherDoesNotMatch() {
Capabilities stereotype =
new ImmutableCapabilities(
CapabilityType.BROWSER_NAME,
"chrome",
CapabilityType.BROWSER_VERSION,
"80",
CapabilityType.PLATFORM_NAME,
Platform.WINDOWS,
"se:slotMatcher_version",
"cust4",
"se:slotMatcherAppName",
"myApp");
Capabilities capabilities =
new ImmutableCapabilities(
CapabilityType.BROWSER_NAME,
"chrome",
CapabilityType.BROWSER_VERSION,
"80",
CapabilityType.PLATFORM_NAME,
Platform.WINDOWS,
"se:slotMatcher_version",
"dev4",
"se:slotMatcherAppName",
"myApp");
assertThat(slotMatcher.matches(stereotype, capabilities)).isFalse();
}

@Test
void matchesWhenPrefixedPlatformVersionIsNotRequested() {
Capabilities stereotype =
Expand Down
Loading