From 09734871826e6a15c34e19baaec217c839b3a2a4 Mon Sep 17 00:00:00 2001 From: Viet Nguyen Duc Date: Thu, 10 Oct 2024 05:34:09 +0000 Subject: [PATCH] [grid]: Capabilities prefix starts with se:slotMatcher for DefaultSlotMatcher decision Signed-off-by: Viet Nguyen Duc --- .../grid/data/DefaultSlotMatcher.java | 20 +++++++++++-- .../grid/data/DefaultSlotMatcherTest.java | 29 +++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/java/src/org/openqa/selenium/grid/data/DefaultSlotMatcher.java b/java/src/org/openqa/selenium/grid/data/DefaultSlotMatcher.java index 594f1061dd6c6..f54cd932263c6 100644 --- a/java/src/org/openqa/selenium/grid/data/DefaultSlotMatcher.java +++ b/java/src/org/openqa/selenium/grid/data/DefaultSlotMatcher.java @@ -50,6 +50,7 @@ public class DefaultSlotMatcher implements SlotMatcher, Serializable { */ private static final List 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) { @@ -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()) @@ -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) { diff --git a/java/test/org/openqa/selenium/grid/data/DefaultSlotMatcherTest.java b/java/test/org/openqa/selenium/grid/data/DefaultSlotMatcherTest.java index 42140dca9ef7e..1b453201dd4b7 100644 --- a/java/test/org/openqa/selenium/grid/data/DefaultSlotMatcherTest.java +++ b/java/test/org/openqa/selenium/grid/data/DefaultSlotMatcherTest.java @@ -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 =