23
23
import static org .assertj .core .api .Assertions .assertThat ;
24
24
import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
25
25
import static org .assertj .core .api .Assumptions .assumeThat ;
26
+ import static org .assertj .core .api .InstanceOfAssertFactories .LIST ;
27
+ import static org .assertj .core .api .InstanceOfAssertFactories .MAP ;
26
28
import static org .openqa .selenium .PageLoadStrategy .EAGER ;
27
29
import static org .openqa .selenium .firefox .FirefoxDriver .Capability .BINARY ;
28
30
import static org .openqa .selenium .firefox .FirefoxDriver .Capability .MARIONETTE ;
@@ -68,9 +70,9 @@ public class FirefoxOptionsTest {
68
70
@ Test
69
71
public void canInitFirefoxOptionsWithCapabilities () {
70
72
FirefoxOptions options = new FirefoxOptions (new ImmutableCapabilities (
71
- MARIONETTE , false ,
72
- PAGE_LOAD_STRATEGY , PageLoadStrategy .EAGER ,
73
- ACCEPT_INSECURE_CERTS , true ));
73
+ MARIONETTE , false ,
74
+ PAGE_LOAD_STRATEGY , PageLoadStrategy .EAGER ,
75
+ ACCEPT_INSECURE_CERTS , true ));
74
76
75
77
assertThat (options .isLegacy ()).isTrue ();
76
78
assertThat (options .getCapability (PAGE_LOAD_STRATEGY )).isEqualTo (EAGER );
@@ -80,7 +82,7 @@ public void canInitFirefoxOptionsWithCapabilities() {
80
82
@ Test
81
83
public void canInitFirefoxOptionsWithCapabilitiesThatContainFirefoxOptions () {
82
84
FirefoxOptions options = new FirefoxOptions ().setLegacy (true ).merge (
83
- new ImmutableCapabilities (PAGE_LOAD_STRATEGY , PageLoadStrategy .EAGER ));
85
+ new ImmutableCapabilities (PAGE_LOAD_STRATEGY , PageLoadStrategy .EAGER ));
84
86
Capabilities caps = new ImmutableCapabilities (FIREFOX_OPTIONS , options );
85
87
86
88
FirefoxOptions options2 = new FirefoxOptions (caps );
@@ -93,7 +95,7 @@ public void canInitFirefoxOptionsWithCapabilitiesThatContainFirefoxOptions() {
93
95
public void canInitFirefoxOptionsWithCapabilitiesThatContainFirefoxOptionsAsMap () {
94
96
FirefoxProfile profile = new FirefoxProfile ();
95
97
Capabilities caps = new ImmutableCapabilities (
96
- FIREFOX_OPTIONS , ImmutableMap .of ("profile" , profile ));
98
+ FIREFOX_OPTIONS , ImmutableMap .of ("profile" , profile ));
97
99
98
100
FirefoxOptions options = new FirefoxOptions (caps );
99
101
@@ -150,8 +152,8 @@ public void stringBasedBinaryRemainsAbsoluteIfSetAsAbsolute() {
150
152
Map <String , Object > json = new FirefoxOptions ().setBinary ("/i/like/cheese" ).asMap ();
151
153
152
154
assertThat (json .get (FIREFOX_OPTIONS ))
153
- .asInstanceOf (InstanceOfAssertFactories .MAP )
154
- .containsEntry ("binary" , "/i/like/cheese" );
155
+ .asInstanceOf (InstanceOfAssertFactories .MAP )
156
+ .containsEntry ("binary" , "/i/like/cheese" );
155
157
}
156
158
157
159
@ Test
@@ -177,7 +179,7 @@ public void shouldPickUpBinaryFromSystemPropertyIfSet() throws IOException {
177
179
FirefoxOptions options = new FirefoxOptions ();
178
180
179
181
FirefoxBinary firefoxBinary =
180
- options .getBinaryOrNull ().orElseThrow (() -> new AssertionError ("No binary" ));
182
+ options .getBinaryOrNull ().orElseThrow (() -> new AssertionError ("No binary" ));
181
183
182
184
assertThat (firefoxBinary .getPath ()).isEqualTo (binary .toString ());
183
185
} finally {
@@ -249,7 +251,7 @@ public void shouldThrowAnExceptionIfSystemPropertyProfileDoesNotExist() {
249
251
try {
250
252
property .set (unlikelyProfileName );
251
253
assertThatExceptionOfType (WebDriverException .class )
252
- .isThrownBy (FirefoxOptions ::new );
254
+ .isThrownBy (FirefoxOptions ::new );
253
255
} finally {
254
256
property .reset ();
255
257
}
@@ -258,7 +260,7 @@ public void shouldThrowAnExceptionIfSystemPropertyProfileDoesNotExist() {
258
260
@ Test
259
261
public void callingToStringWhenTheBinaryDoesNotExistShouldNotCauseAnException () {
260
262
FirefoxOptions options =
261
- new FirefoxOptions ().setBinary ("there's nothing better in life than cake or peas." );
263
+ new FirefoxOptions ().setBinary ("there's nothing better in life than cake or peas." );
262
264
options .toString ();
263
265
// The binary does not exist on this machine, but could do elsewhere. Be chill.
264
266
}
@@ -277,45 +279,46 @@ public void canBuildLogLevelFromStringRepresentation() {
277
279
@ Test
278
280
public void canConvertOptionsWithArgsToCapabilitiesAndRestoreBack () {
279
281
FirefoxOptions options = new FirefoxOptions (
280
- new MutableCapabilities (new FirefoxOptions ().addArguments ("-a" , "-b" )));
282
+ new MutableCapabilities (new FirefoxOptions ().addArguments ("-a" , "-b" )));
281
283
Object options2 = options .asMap ().get (FirefoxOptions .FIREFOX_OPTIONS );
282
284
assertThat (options2 )
283
- .asInstanceOf (InstanceOfAssertFactories .MAP )
284
- .containsEntry ("args" , Arrays .asList ("-a" , "-b" ));
285
+ .asInstanceOf (InstanceOfAssertFactories .MAP )
286
+ .containsEntry ("args" , Arrays .asList ("-a" , "-b" ));
285
287
}
286
288
287
289
@ Test
288
290
public void canConvertOptionsWithPrefsToCapabilitiesAndRestoreBack () {
289
291
FirefoxOptions options = new FirefoxOptions (
290
- new MutableCapabilities (new FirefoxOptions ()
291
- .addPreference ("string.pref" , "some value" )
292
- .addPreference ("int.pref" , 42 )
293
- .addPreference ("boolean.pref" , true )));
292
+ new MutableCapabilities (
293
+ new FirefoxOptions ()
294
+ .addPreference ("string.pref" , "some value" )
295
+ .addPreference ("int.pref" , 42 )
296
+ .addPreference ("boolean.pref" , true )));
294
297
Object options2 = options .asMap ().get (FirefoxOptions .FIREFOX_OPTIONS );
295
298
assertThat (options2 )
296
- .asInstanceOf (InstanceOfAssertFactories .MAP )
297
- .extractingByKey ("prefs" )
298
- .asInstanceOf (InstanceOfAssertFactories .MAP )
299
- .containsEntry ("string.pref" , "some value" )
300
- .containsEntry ("int.pref" , 42 )
301
- .containsEntry ("boolean.pref" , true );
299
+ .asInstanceOf (InstanceOfAssertFactories .MAP )
300
+ .extractingByKey ("prefs" )
301
+ .asInstanceOf (InstanceOfAssertFactories .MAP )
302
+ .containsEntry ("string.pref" , "some value" )
303
+ .containsEntry ("int.pref" , 42 )
304
+ .containsEntry ("boolean.pref" , true );
302
305
}
303
306
304
307
@ Test
305
308
public void canConvertOptionsWithBinaryToCapabilitiesAndRestoreBack () {
306
309
FirefoxOptions options = new FirefoxOptions (
307
- new MutableCapabilities (new FirefoxOptions ().setBinary (new FirefoxBinary ())));
310
+ new MutableCapabilities (new FirefoxOptions ().setBinary (new FirefoxBinary ())));
308
311
Object options2 = options .asMap ().get (FirefoxOptions .FIREFOX_OPTIONS );
309
312
assertThat (options2 )
310
- .asInstanceOf (InstanceOfAssertFactories .MAP )
311
- .containsEntry ("binary" , new FirefoxBinary ().getPath ().replaceAll ("\\ \\ " , "/" ));
313
+ .asInstanceOf (InstanceOfAssertFactories .MAP )
314
+ .containsEntry ("binary" , new FirefoxBinary ().getPath ().replaceAll ("\\ \\ " , "/" ));
312
315
}
313
316
314
317
@ Test
315
318
public void roundTrippingToCapabilitiesAndBackWorks () {
316
319
FirefoxOptions expected = new FirefoxOptions ()
317
- .setLegacy (true )
318
- .addPreference ("cake" , "walk" );
320
+ .setLegacy (true )
321
+ .addPreference ("cake" , "walk" );
319
322
320
323
// Convert to a Map so we can create a standalone capabilities instance, which we then use to
321
324
// create a new set of options. This is the round trip, ladies and gentlemen.
@@ -328,19 +331,49 @@ public void roundTrippingToCapabilitiesAndBackWorks() {
328
331
public void optionsAsMapShouldBeImmutable () {
329
332
Map <String , Object > options = new FirefoxOptions ().asMap ();
330
333
assertThatExceptionOfType (UnsupportedOperationException .class )
331
- .isThrownBy (() -> options .put ("browserName" , "chrome" ));
334
+ .isThrownBy (() -> options .put ("browserName" , "chrome" ));
332
335
333
336
Map <String , Object > mozOptions = (Map <String , Object >) options .get (FIREFOX_OPTIONS );
334
337
assertThatExceptionOfType (UnsupportedOperationException .class )
335
- .isThrownBy (() -> mozOptions .put ("prefs" , emptyMap ()));
338
+ .isThrownBy (() -> mozOptions .put ("prefs" , emptyMap ()));
336
339
337
340
Map <String , Object > prefs = (Map <String , Object >) mozOptions .get ("prefs" );
338
341
assertThatExceptionOfType (UnsupportedOperationException .class )
339
- .isThrownBy (() -> prefs .put ("x" , true ));
342
+ .isThrownBy (() -> prefs .put ("x" , true ));
340
343
341
344
List <String > args = (List <String >) mozOptions .get ("args" );
342
345
assertThatExceptionOfType (UnsupportedOperationException .class )
343
- .isThrownBy (() -> args .add ("-help" ));
346
+ .isThrownBy (() -> args .add ("-help" ));
347
+ }
348
+
349
+ @ Test
350
+ public void mergingOptionsMergesArguments () {
351
+ FirefoxOptions one = new FirefoxOptions ().addArguments ("verbose" );
352
+ FirefoxOptions two = new FirefoxOptions ().addArguments ("silent" );
353
+ FirefoxOptions merged = one .merge (two );
354
+
355
+ assertThat (merged .asMap ()).asInstanceOf (MAP )
356
+ .extractingByKey (FirefoxOptions .FIREFOX_OPTIONS ).asInstanceOf (MAP )
357
+ .extractingByKey ("args" ).asInstanceOf (LIST )
358
+ .containsExactly ("verbose" , "silent" );
359
+ }
360
+
361
+ @ Test
362
+ public void mergingOptionsMergesPreferences () {
363
+ FirefoxOptions one = new FirefoxOptions ()
364
+ .addPreference ("opt1" , "val1" )
365
+ .addPreference ("opt2" , "val2" );
366
+ FirefoxOptions two = new FirefoxOptions ()
367
+ .addPreference ("opt2" , "val4" )
368
+ .addPreference ("opt3" , "val3" );
369
+ FirefoxOptions merged = one .merge (two );
370
+
371
+ assertThat (merged .asMap ()).asInstanceOf (MAP )
372
+ .extractingByKey (FirefoxOptions .FIREFOX_OPTIONS ).asInstanceOf (MAP )
373
+ .extractingByKey ("prefs" ).asInstanceOf (MAP )
374
+ .containsEntry ("opt1" , "val1" )
375
+ .containsEntry ("opt2" , "val4" )
376
+ .containsEntry ("opt3" , "val3" );
344
377
}
345
378
346
379
private static class JreSystemProperty {
0 commit comments