22
22
import com .google .common .collect .ImmutableSet ;
23
23
24
24
import org .openqa .selenium .AcceptedW3CCapabilityKeys ;
25
- import org .openqa .selenium .Capabilities ;
26
- import org .openqa .selenium .ImmutableCapabilities ;
27
- import org .openqa .selenium .Proxy ;
28
25
import org .openqa .selenium .internal .Require ;
29
26
import org .openqa .selenium .remote .session .CapabilitiesFilter ;
30
27
import org .openqa .selenium .remote .session .CapabilityTransform ;
31
28
import org .openqa .selenium .remote .session .ProxyTransform ;
32
29
import org .openqa .selenium .remote .session .StripAnyPlatform ;
33
30
import org .openqa .selenium .remote .session .W3CPlatformNameNormaliser ;
34
31
35
- import java .util .Arrays ;
36
32
import java .util .Collection ;
37
- import java .util .HashMap ;
38
33
import java .util .HashSet ;
39
34
import java .util .LinkedList ;
40
35
import java .util .List ;
48
43
import java .util .stream .Collectors ;
49
44
import java .util .stream .Stream ;
50
45
51
- import static org .openqa .selenium .remote .CapabilityType .PLATFORM ;
52
- import static org .openqa .selenium .remote .CapabilityType .PLATFORM_NAME ;
53
- import static org .openqa .selenium .remote .CapabilityType .PROXY ;
54
-
55
46
public class CapabilitiesUtils {
56
47
57
48
private static final Predicate <String > ACCEPTED_W3C_PATTERNS = new AcceptedW3CCapabilityKeys ();
@@ -60,12 +51,6 @@ private CapabilitiesUtils() {
60
51
// Helper class
61
52
}
62
53
63
- public static Stream <Capabilities > makeW3CSafe (Capabilities possiblyInvalidCapabilities ) {
64
- Require .nonNull ("Capabilities" , possiblyInvalidCapabilities );
65
-
66
- return makeW3CSafe (possiblyInvalidCapabilities .asMap ()).map (ImmutableCapabilities ::new );
67
- }
68
-
69
54
public static Stream <Map <String , Object >> makeW3CSafe (Map <String , Object > possiblyInvalidCapabilities ) {
70
55
Require .nonNull ("Capabilities" , possiblyInvalidCapabilities );
71
56
@@ -75,13 +60,12 @@ public static Stream<Map<String, Object>> makeW3CSafe(Map<String, Object> possib
75
60
// then add magic to generate each of the w3c capabilities. For the sake of simplicity, we're
76
61
// going to make the (probably wrong) assumption we can hold all of the firstMatch values and
77
62
// alwaysMatch value in memory at the same time.
78
- Map <String , Object > oss = convertOssToW3C (possiblyInvalidCapabilities );
79
63
Stream <Map <String , Object >> fromOss ;
80
64
Set <String > usedKeys = new HashSet <>();
81
65
82
66
// Are there any values we care want to pull out into a mapping of their own?
83
67
List <Map <String , Object >> firsts = adapters .stream ()
84
- .map (adapter -> adapter .apply (oss ))
68
+ .map (adapter -> adapter .apply (possiblyInvalidCapabilities ))
85
69
.filter (Objects ::nonNull )
86
70
.filter (map -> !map .isEmpty ())
87
71
.map (
@@ -97,7 +81,7 @@ public static Stream<Map<String, Object>> makeW3CSafe(Map<String, Object> possib
97
81
}
98
82
99
83
// Are there any remaining unused keys?
100
- Map <String , Object > always = oss .entrySet ().stream ()
84
+ Map <String , Object > always = possiblyInvalidCapabilities .entrySet ().stream ()
101
85
.filter (entry -> !usedKeys .contains (entry .getKey ()))
102
86
.filter (entry -> entry .getValue () != null )
103
87
.collect (ImmutableMap .toImmutableMap (Map .Entry ::getKey , Map .Entry ::getValue ));
@@ -114,42 +98,7 @@ public static Stream<Map<String, Object>> makeW3CSafe(Map<String, Object> possib
114
98
return fromOss ;
115
99
}
116
100
117
- private static Map <String , Object > convertOssToW3C (Map <String , Object > capabilities ) {
118
- Map <String , Object > toReturn = new TreeMap <>(capabilities );
119
-
120
- // Platform name
121
- if (capabilities .containsKey (PLATFORM ) && !capabilities .containsKey (PLATFORM_NAME )) {
122
- toReturn .put (PLATFORM_NAME , String .valueOf (capabilities .get (PLATFORM )));
123
- }
124
-
125
- if (capabilities .containsKey (PROXY )) {
126
- Map <String , Object > proxyMap = getProxyFromCapabilities (capabilities );
127
- if (proxyMap .containsKey ("noProxy" )) {
128
- Map <String , Object > w3cProxyMap = new HashMap <>(proxyMap );
129
- Object rawData = proxyMap .get ("noProxy" );
130
- if (rawData instanceof String ) {
131
- w3cProxyMap .put ("noProxy" , Arrays .asList (((String ) rawData ).split (",\\ s*" )));
132
- }
133
- toReturn .put (CapabilityType .PROXY , w3cProxyMap );
134
- }
135
- }
136
-
137
- return toReturn ;
138
- }
139
-
140
- private static Map <String , Object > getProxyFromCapabilities (Map <String , Object > capabilities ) {
141
- Object rawProxy = capabilities .get (CapabilityType .PROXY );
142
- if (rawProxy instanceof Proxy ) {
143
- return ((Proxy ) rawProxy ).toJson ();
144
- } else if (rawProxy instanceof Map ) {
145
- //noinspection unchecked
146
- return (Map <String , Object >) rawProxy ;
147
- } else {
148
- return new HashMap <>();
149
- }
150
- }
151
-
152
- private static Map <String , Object > applyTransforms (Map <String , Object > caps ) {
101
+ public static Map <String , Object > applyTransforms (Map <String , Object > caps ) {
153
102
Queue <Map .Entry <String , Object >> toExamine = new LinkedList <>(caps .entrySet ());
154
103
Set <String > seenKeys = new HashSet <>();
155
104
Map <String , Object > toReturn = new TreeMap <>();
0 commit comments