24
24
import static org .openqa .selenium .chrome .ChromeDriverLogLevel .OFF ;
25
25
import static org .openqa .selenium .chrome .ChromeDriverLogLevel .SEVERE ;
26
26
27
+ import java .io .File ;
28
+ import java .util .Base64 ;
27
29
import java .util .List ;
28
30
import java .util .Map ;
29
31
import org .junit .Test ;
30
32
import org .junit .experimental .categories .Category ;
33
+ import org .openqa .selenium .testing .TestUtilities ;
31
34
import org .openqa .selenium .testing .UnitTests ;
32
35
33
36
@ Category (UnitTests .class )
@@ -37,19 +40,19 @@ public class ChromeOptionsTest {
37
40
public void optionsAsMapShouldBeImmutable () {
38
41
Map <String , Object > options = new ChromeOptions ().asMap ();
39
42
assertThatExceptionOfType (UnsupportedOperationException .class )
40
- .isThrownBy (() -> options .put ("browserType" , "firefox" ));
43
+ .isThrownBy (() -> options .put ("browserType" , "firefox" ));
41
44
42
45
Map <String , Object > googOptions = (Map <String , Object >) options .get (ChromeOptions .CAPABILITY );
43
46
assertThatExceptionOfType (UnsupportedOperationException .class )
44
- .isThrownBy (() -> googOptions .put ("binary" , "" ));
47
+ .isThrownBy (() -> googOptions .put ("binary" , "" ));
45
48
46
49
List <String > extensions = (List <String >) googOptions .get ("extensions" );
47
50
assertThatExceptionOfType (UnsupportedOperationException .class )
48
- .isThrownBy (() -> extensions .add ("x" ));
51
+ .isThrownBy (() -> extensions .add ("x" ));
49
52
50
53
List <String > args = (List <String >) googOptions .get ("args" );
51
54
assertThatExceptionOfType (UnsupportedOperationException .class )
52
- .isThrownBy (() -> args .add ("-help" ));
55
+ .isThrownBy (() -> args .add ("-help" ));
53
56
}
54
57
55
58
@ Test
@@ -69,4 +72,69 @@ public void mergingOptionsMergesArguments() {
69
72
.extractingByKey ("args" ).asInstanceOf (LIST )
70
73
.containsExactly ("verbose" , "silent" );
71
74
}
75
+
76
+ @ Test
77
+ public void mergingOptionsMergesEncodedExtensions () {
78
+ String ext1 = Base64 .getEncoder ().encodeToString ("ext1" .getBytes ());
79
+ String ext2 = Base64 .getEncoder ().encodeToString ("ext2" .getBytes ());
80
+
81
+ ChromeOptions one = new ChromeOptions ().addEncodedExtensions (ext1 );
82
+ ChromeOptions two = new ChromeOptions ().addEncodedExtensions (ext2 );
83
+ ChromeOptions merged = one .merge (two );
84
+
85
+ assertThat (merged .asMap ()).asInstanceOf (MAP )
86
+ .extractingByKey (ChromeOptions .CAPABILITY ).asInstanceOf (MAP )
87
+ .extractingByKey ("extensions" ).asInstanceOf (LIST )
88
+ .containsExactly (ext1 , ext2 );
89
+ }
90
+
91
+ @ Test
92
+ public void mergingOptionsMergesExtensions () {
93
+ File ext1 = TestUtilities .createTmpFile ("ext1" );
94
+ String ext1Encoded = Base64 .getEncoder ().encodeToString ("ext1" .getBytes ());
95
+ File ext2 = TestUtilities .createTmpFile ("ext2" );
96
+ String ext2Encoded = Base64 .getEncoder ().encodeToString ("ext2" .getBytes ());
97
+
98
+ ChromeOptions one = new ChromeOptions ().addExtensions (ext1 );
99
+ ChromeOptions two = new ChromeOptions ().addExtensions (ext2 );
100
+ ChromeOptions merged = one .merge (two );
101
+
102
+ assertThat (merged .asMap ()).asInstanceOf (MAP )
103
+ .extractingByKey (ChromeOptions .CAPABILITY ).asInstanceOf (MAP )
104
+ .extractingByKey ("extensions" ).asInstanceOf (LIST )
105
+ .containsExactly (ext1Encoded , ext2Encoded );
106
+ }
107
+
108
+ @ Test
109
+ public void mergingOptionsMergesEncodedExtensionsAndFileExtensions () {
110
+ File ext1 = TestUtilities .createTmpFile ("ext1" );
111
+ String ext1Encoded = Base64 .getEncoder ().encodeToString ("ext1" .getBytes ());
112
+ String ext2 = Base64 .getEncoder ().encodeToString ("ext2" .getBytes ());
113
+
114
+ ChromeOptions one = new ChromeOptions ().addExtensions (ext1 );
115
+ ChromeOptions two = new ChromeOptions ().addEncodedExtensions (ext2 );
116
+ ChromeOptions merged = one .merge (two );
117
+
118
+ assertThat (merged .asMap ()).asInstanceOf (MAP )
119
+ .extractingByKey (ChromeOptions .CAPABILITY ).asInstanceOf (MAP )
120
+ .extractingByKey ("extensions" ).asInstanceOf (LIST )
121
+ .containsExactly (ext1Encoded , ext2 );
122
+ }
123
+
124
+ @ Test
125
+ public void mergingOptionsMergesExperimentalOptions () {
126
+ ChromeOptions one = new ChromeOptions ()
127
+ .setExperimentalOption ("opt1" , "val1" )
128
+ .setExperimentalOption ("opt2" , "val2" );
129
+ ChromeOptions two = new ChromeOptions ()
130
+ .setExperimentalOption ("opt2" , "val4" )
131
+ .setExperimentalOption ("opt3" , "val3" );
132
+ ChromeOptions merged = one .merge (two );
133
+
134
+ assertThat (merged .asMap ()).asInstanceOf (MAP )
135
+ .extractingByKey (ChromeOptions .CAPABILITY ).asInstanceOf (MAP )
136
+ .containsEntry ("opt1" , "val1" )
137
+ .containsEntry ("opt2" , "val4" )
138
+ .containsEntry ("opt3" , "val3" );
139
+ }
72
140
}
0 commit comments