@@ -47,34 +47,36 @@ public SessionCapabilitiesMutator(Capabilities slotStereotype) {
4747
4848 @ Override
4949 public Capabilities apply (Capabilities capabilities ) {
50+ if (!Objects .equals (slotStereotype .getBrowserName (), capabilities .getBrowserName ())) {
51+ return capabilities ;
52+ }
53+
5054 if (slotStereotype .getCapability (SE_VNC_ENABLED ) != null ) {
5155 capabilities = new PersistentCapabilities (capabilities )
5256 .setCapability (SE_VNC_ENABLED , slotStereotype .getCapability (SE_VNC_ENABLED ))
5357 .setCapability (SE_NO_VNC_PORT , slotStereotype .getCapability (SE_NO_VNC_PORT ));
5458 }
5559
56- if (!Objects .equals (slotStereotype .getBrowserName (), capabilities .getBrowserName ())) {
57- return capabilities ;
58- }
60+ String browserName = capabilities .getBrowserName ().toLowerCase ();
5961
60- if ("internet explorer" .equalsIgnoreCase (capabilities . getBrowserName () )) {
62+ if ("internet explorer" .equalsIgnoreCase (browserName )) {
6163 return new ImmutableCapabilities (removeUnknownExtensionsForIE (capabilities ));
6264 }
6365
64- String browserName = capabilities .getBrowserName ().toLowerCase ();
6566 if (!BROWSER_OPTIONS .containsKey (browserName )) {
6667 return capabilities ;
6768 }
69+
6870 String options = BROWSER_OPTIONS .get (browserName );
6971 if (slotStereotype .asMap ().containsKey (options ) && capabilities .asMap ().containsKey (options )) {
7072
7173 @ 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 ));
7576
7677 @ 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 ));
7880
7981 // Merge top level capabilities, excluding browser specific options.
8082 // 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
118120 String name = entry .getKey ();
119121 Object value = entry .getValue ();
120122 if (name .equals ("args" )) {
121- List <String > arguments = (List <String >) value ;
123+ @ SuppressWarnings ("unchecked" )
124+ List <String > arguments = new ArrayList <>((List <String >) value );
122125
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 <>())));
125129
126130 arguments .forEach (arg -> {
127131 if (!stereotypeArguments .contains (arg )) {
@@ -132,10 +136,12 @@ private Map<String, Object> mergeChromiumOptions(Map<String, Object> stereotypeO
132136 }
133137
134138 if (name .equals ("extensions" )) {
135- List <String > extensionList = (List <String >) value ;
139+ @ SuppressWarnings ("unchecked" )
140+ List <String > extensionList = new ArrayList <>((List <String >) value );
136141
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 <>())));
139145
140146 extensionList .forEach (extension -> {
141147 if (!stereotypeExtensions .contains (extension )) {
@@ -162,9 +168,13 @@ private Map<String, Object> mergeFirefoxOptions(Map<String, Object> stereotypeOp
162168 String name = entry .getKey ();
163169 Object value = entry .getValue ();
164170 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+
168178 arguments .forEach (arg -> {
169179 if (!stereotypeArguments .contains (arg )) {
170180 stereotypeArguments .add (arg );
@@ -174,10 +184,12 @@ private Map<String, Object> mergeFirefoxOptions(Map<String, Object> stereotypeOp
174184 }
175185
176186 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 );
178189
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 <>())));
181193
182194 stereotypePrefs .putAll (prefs );
183195 toReturn .put ("prefs" , stereotypePrefs );
@@ -189,6 +201,7 @@ private Map<String, Object> mergeFirefoxOptions(Map<String, Object> stereotypeOp
189201 }
190202
191203 if (name .equals ("log" )) {
204+ @ SuppressWarnings ("unchecked" )
192205 Map <String , Object > logLevelMap = (Map <String , Object >) value ;
193206 toReturn .put ("log" , logLevelMap );
194207 }
0 commit comments