1818package org .openqa .selenium .grid .data ;
1919
2020import java .io .Serializable ;
21- import java .util .Arrays ;
22- import java .util .List ;
2321import java .util .Objects ;
2422import org .openqa .selenium .Capabilities ;
2523
4442 */
4543public class DefaultSlotMatcher implements SlotMatcher , Serializable {
4644
47- /*
48- List of prefixed extension capabilities we never should try to match, they should be
49- matched in the Node or in the browser driver.
50- */
51- private static final List <String > EXTENSION_CAPABILITIES_PREFIXES =
52- Arrays .asList ("goog:" , "moz:" , "ms:" , "se:" );
53-
5445 @ Override
5546 public boolean matches (Capabilities stereotype , Capabilities capabilities ) {
5647
@@ -76,12 +67,13 @@ public boolean matches(Capabilities stereotype, Capabilities capabilities) {
7667
7768 // At the end, a simple browser, browserVersion and platformName match
7869 boolean browserNameMatch =
79- (capabilities .getBrowserName () == null || capabilities .getBrowserName ().isEmpty ())
70+ capabilities .getBrowserName () == null
71+ || capabilities .getBrowserName ().isEmpty ()
8072 || Objects .equals (stereotype .getBrowserName (), capabilities .getBrowserName ());
8173 boolean browserVersionMatch =
82- ( capabilities .getBrowserVersion () == null
83- || capabilities .getBrowserVersion ().isEmpty ()
84- || Objects .equals (capabilities .getBrowserVersion (), "stable" ) )
74+ capabilities .getBrowserVersion () == null
75+ || capabilities .getBrowserVersion ().isEmpty ()
76+ || Objects .equals (capabilities .getBrowserVersion (), "stable" )
8577 || Objects .equals (stereotype .getBrowserVersion (), capabilities .getBrowserVersion ());
8678 boolean platformNameMatch =
8779 capabilities .getPlatformName () == null
@@ -97,18 +89,16 @@ private Boolean initialMatch(Capabilities stereotype, Capabilities capabilities)
9789 .filter (name -> !name .contains (":" ))
9890 // Platform matching is special, we do it later
9991 .filter (name -> !"platformName" .equalsIgnoreCase (name ))
92+ .filter (name -> capabilities .getCapability (name ) != null )
10093 .map (
10194 name -> {
102- if (capabilities .getCapability (name ) instanceof String ) {
103- return stereotype
104- .getCapability (name )
105- .toString ()
106- .equalsIgnoreCase (capabilities .getCapability (name ).toString ());
107- } else {
108- return capabilities .getCapability (name ) == null
109- || Objects .equals (
110- stereotype .getCapability (name ), capabilities .getCapability (name ));
95+ if (stereotype .getCapability (name ) instanceof String
96+ && capabilities .getCapability (name ) instanceof String ) {
97+ return ((String ) stereotype .getCapability (name ))
98+ .equalsIgnoreCase ((String ) capabilities .getCapability (name ));
11199 }
100+ return Objects .equals (
101+ stereotype .getCapability (name ), capabilities .getCapability (name ));
112102 })
113103 .reduce (Boolean ::logicalAnd )
114104 .orElse (true );
@@ -145,27 +135,22 @@ private Boolean platformVersionMatch(Capabilities stereotype, Capabilities capab
145135 }
146136
147137 private Boolean extensionCapabilitiesMatch (Capabilities stereotype , Capabilities capabilities ) {
148- /*
149- We match extension capabilities when they are not prefixed with any of the
150- EXTENSION_CAPABILITIES_PREFIXES items. Also, we match them only when the capabilities
151- of the new session request contains that specific extension capability.
152- */
153138 return stereotype .getCapabilityNames ().stream ()
154139 .filter (name -> name .contains (":" ))
155- .filter (name -> capabilities .asMap ().containsKey (name ))
156- .filter (name -> EXTENSION_CAPABILITIES_PREFIXES .stream ().noneMatch (name ::contains ))
140+ .filter (name -> capabilities .getCapability (name ) != null )
157141 .map (
158142 name -> {
159- if (capabilities .getCapability (name ) instanceof String ) {
160- return stereotype
161- .getCapability (name )
162- .toString ()
163- . equalsIgnoreCase ( capabilities . getCapability ( name ). toString ());
164- } else {
165- return capabilities .getCapability (name ) == null
166- || Objects .equals (
167- stereotype .getCapability (name ), capabilities .getCapability (name ));
143+ if (stereotype .getCapability (name ) instanceof String
144+ && capabilities . getCapability ( name ) instanceof String ) {
145+ return (( String ) stereotype .getCapability (name ) )
146+ .equalsIgnoreCase (( String ) capabilities . getCapability ( name ));
147+ }
148+ if ( capabilities . getCapability ( name ) instanceof Number
149+ || capabilities .getCapability (name ) instanceof Boolean ) {
150+ return Objects .equals (
151+ stereotype .getCapability (name ), capabilities .getCapability (name ));
168152 }
153+ return true ;
169154 })
170155 .reduce (Boolean ::logicalAnd )
171156 .orElse (true );
0 commit comments