17
17
18
18
package org .openqa .selenium .remote .session ;
19
19
20
- import org .openqa .selenium .remote .CapabilityType ;
21
-
22
20
import java .util .Map ;
23
21
import java .util .Objects ;
24
22
import java .util .TreeMap ;
25
23
import java .util .stream .Collectors ;
26
24
27
25
import static org .openqa .selenium .remote .Browser .CHROME ;
26
+ import static org .openqa .selenium .remote .CapabilityType .BROWSER_NAME ;
28
27
29
28
public class ChromeFilter implements CapabilitiesFilter {
30
29
@ Override
31
30
public Map <String , Object > apply (Map <String , Object > unmodifiedCaps ) {
31
+ String browserName = (String ) unmodifiedCaps .getOrDefault (BROWSER_NAME , "" );
32
32
Map <String , Object > caps = unmodifiedCaps .entrySet ().parallelStream ()
33
33
.filter (
34
34
entry ->
35
- (CapabilityType . BROWSER_NAME .equals (entry .getKey ()) && CHROME .is (String .valueOf (entry .getValue ()))) ||
35
+ (BROWSER_NAME .equals (entry .getKey ()) && CHROME .is (String .valueOf (entry .getValue ()))) ||
36
36
entry .getKey ().startsWith ("goog:" ) ||
37
37
"chromeOptions" .equals (entry .getKey ()) ||
38
- "loggingPrefs" .equals (entry .getKey ()))
38
+ ( "loggingPrefs" .equals (entry .getKey ()) && CHROME . is ( browserName )))
39
39
.filter (entry -> Objects .nonNull (entry .getValue ()))
40
40
.distinct ()
41
41
.collect (Collectors .toMap (
@@ -45,11 +45,13 @@ public Map<String, Object> apply(Map<String, Object> unmodifiedCaps) {
45
45
TreeMap ::new ));
46
46
47
47
// We may need to map the chromeoptions to the new form
48
- if (caps .containsKey ("chromeOptions" ) && !caps .containsKey ("goog:chromeOptions" )) {
48
+ if (caps .containsKey ("chromeOptions" ) && !caps .containsKey ("goog:chromeOptions" )
49
+ && CHROME .is (browserName )) {
49
50
caps .put ("goog:chromeOptions" , caps .get ("chromeOptions" ));
50
51
}
51
52
52
- if (caps .containsKey ("loggingPrefs" ) && !caps .containsKey ("goog:loggingPrefs" )) {
53
+ if (caps .containsKey ("loggingPrefs" ) && !caps .containsKey ("goog:loggingPrefs" )
54
+ && CHROME .is (browserName )) {
53
55
caps .put ("goog:loggingPrefs" , caps .get ("loggingPrefs" ));
54
56
}
55
57
0 commit comments