@@ -47,34 +47,36 @@ public SessionCapabilitiesMutator(Capabilities slotStereotype) {
47
47
48
48
@ Override
49
49
public Capabilities apply (Capabilities capabilities ) {
50
+ if (!Objects .equals (slotStereotype .getBrowserName (), capabilities .getBrowserName ())) {
51
+ return capabilities ;
52
+ }
53
+
50
54
if (slotStereotype .getCapability (SE_VNC_ENABLED ) != null ) {
51
55
capabilities = new PersistentCapabilities (capabilities )
52
56
.setCapability (SE_VNC_ENABLED , slotStereotype .getCapability (SE_VNC_ENABLED ))
53
57
.setCapability (SE_NO_VNC_PORT , slotStereotype .getCapability (SE_NO_VNC_PORT ));
54
58
}
55
59
56
- if (!Objects .equals (slotStereotype .getBrowserName (), capabilities .getBrowserName ())) {
57
- return capabilities ;
58
- }
60
+ String browserName = capabilities .getBrowserName ().toLowerCase ();
59
61
60
- if ("internet explorer" .equalsIgnoreCase (capabilities . getBrowserName () )) {
62
+ if ("internet explorer" .equalsIgnoreCase (browserName )) {
61
63
return new ImmutableCapabilities (removeUnknownExtensionsForIE (capabilities ));
62
64
}
63
65
64
- String browserName = capabilities .getBrowserName ().toLowerCase ();
65
66
if (!BROWSER_OPTIONS .containsKey (browserName )) {
66
67
return capabilities ;
67
68
}
69
+
68
70
String options = BROWSER_OPTIONS .get (browserName );
69
71
if (slotStereotype .asMap ().containsKey (options ) && capabilities .asMap ().containsKey (options )) {
70
72
71
73
@ SuppressWarnings ("unchecked" )
72
- Map <String , Object >
73
- stereotypeOptions =
74
- (Map <String , Object >) slotStereotype .asMap ().get (options );
74
+ Map <String , Object > stereotypeOptions =
75
+ new HashMap <>((Map <String , Object >) slotStereotype .asMap ().get (options ));
75
76
76
77
@ SuppressWarnings ("unchecked" )
77
- Map <String , Object > capsOptions = (Map <String , Object >) capabilities .asMap ().get (options );
78
+ Map <String , Object > capsOptions =
79
+ new HashMap <>((Map <String , Object >) capabilities .asMap ().get (options ));
78
80
79
81
// Merge top level capabilities, excluding browser specific options.
80
82
// This will overwrite the browser options too, but it does not matter since we tackle it separately just after this.
@@ -118,10 +120,12 @@ private Map<String, Object> mergeChromiumOptions(Map<String, Object> stereotypeO
118
120
String name = entry .getKey ();
119
121
Object value = entry .getValue ();
120
122
if (name .equals ("args" )) {
121
- List <String > arguments = (List <String >) value ;
123
+ @ SuppressWarnings ("unchecked" )
124
+ List <String > arguments = new ArrayList <>((List <String >) value );
122
125
123
- List <String > stereotypeArguments =
124
- (List <String >) (stereotypeOptions .getOrDefault (("args" ), new ArrayList <>()));
126
+ @ SuppressWarnings ("unchecked" )
127
+ List <String > stereotypeArguments = new ArrayList <>(
128
+ (List <String >) (stereotypeOptions .getOrDefault (("args" ), new ArrayList <>())));
125
129
126
130
arguments .forEach (arg -> {
127
131
if (!stereotypeArguments .contains (arg )) {
@@ -132,10 +136,12 @@ private Map<String, Object> mergeChromiumOptions(Map<String, Object> stereotypeO
132
136
}
133
137
134
138
if (name .equals ("extensions" )) {
135
- List <String > extensionList = (List <String >) value ;
139
+ @ SuppressWarnings ("unchecked" )
140
+ List <String > extensionList = new ArrayList <>((List <String >) value );
136
141
137
- List <String > stereotypeExtensions =
138
- (List <String >) (stereotypeOptions .getOrDefault (("extensions" ), new ArrayList <>()));
142
+ @ SuppressWarnings ("unchecked" )
143
+ List <String > stereotypeExtensions = new ArrayList <>(
144
+ (List <String >) (stereotypeOptions .getOrDefault (("extensions" ), new ArrayList <>())));
139
145
140
146
extensionList .forEach (extension -> {
141
147
if (!stereotypeExtensions .contains (extension )) {
@@ -162,9 +168,13 @@ private Map<String, Object> mergeFirefoxOptions(Map<String, Object> stereotypeOp
162
168
String name = entry .getKey ();
163
169
Object value = entry .getValue ();
164
170
if (name .equals ("args" )) {
165
- List <String > arguments = (List <String >) value ;
166
- List <String > stereotypeArguments =
167
- (List <String >) (stereotypeOptions .getOrDefault (("args" ), new ArrayList <>()));
171
+ @ SuppressWarnings ("unchecked" )
172
+ List <String > arguments = new ArrayList <>((List <String >) value );
173
+
174
+ @ SuppressWarnings ("unchecked" )
175
+ List <String > stereotypeArguments = new ArrayList <>(
176
+ (List <String >) (stereotypeOptions .getOrDefault (("args" ), new ArrayList <>())));
177
+
168
178
arguments .forEach (arg -> {
169
179
if (!stereotypeArguments .contains (arg )) {
170
180
stereotypeArguments .add (arg );
@@ -174,10 +184,12 @@ private Map<String, Object> mergeFirefoxOptions(Map<String, Object> stereotypeOp
174
184
}
175
185
176
186
if (name .equals ("prefs" )) {
177
- Map <String , Object > prefs = (Map <String , Object >) value ;
187
+ @ SuppressWarnings ("unchecked" )
188
+ Map <String , Object > prefs = new HashMap <> ((Map <String , Object >) value );
178
189
179
- Map <String , Object > stereotypePrefs =
180
- (Map <String , Object >) (stereotypeOptions .getOrDefault (("prefs" ), new HashMap <>()));
190
+ @ SuppressWarnings ("unchecked" )
191
+ Map <String , Object > stereotypePrefs = new HashMap <>(
192
+ (Map <String , Object >) (stereotypeOptions .getOrDefault (("prefs" ), new HashMap <>())));
181
193
182
194
stereotypePrefs .putAll (prefs );
183
195
toReturn .put ("prefs" , stereotypePrefs );
@@ -189,6 +201,7 @@ private Map<String, Object> mergeFirefoxOptions(Map<String, Object> stereotypeOp
189
201
}
190
202
191
203
if (name .equals ("log" )) {
204
+ @ SuppressWarnings ("unchecked" )
192
205
Map <String , Object > logLevelMap = (Map <String , Object >) value ;
193
206
toReturn .put ("log" , logLevelMap );
194
207
}
0 commit comments