|
20 | 20 | import org.junit.jupiter.api.Test; |
21 | 21 | import org.junit.jupiter.api.Tag; |
22 | 22 | import org.openqa.selenium.AcceptedW3CCapabilityKeys; |
| 23 | +import org.openqa.selenium.MutableCapabilities; |
23 | 24 | import org.openqa.selenium.PageLoadStrategy; |
24 | 25 | import org.openqa.selenium.UnexpectedAlertBehaviour; |
25 | 26 | import org.openqa.selenium.testing.TestUtilities; |
|
37 | 38 | import static org.assertj.core.api.Assertions.assertThat; |
38 | 39 | import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
39 | 40 | import static org.assertj.core.api.InstanceOfAssertFactories.LIST; |
| 41 | +import static org.assertj.core.api.InstanceOfAssertFactories.STRING; |
40 | 42 | import static org.assertj.core.api.InstanceOfAssertFactories.MAP; |
41 | 43 | import static org.openqa.selenium.chrome.ChromeDriverLogLevel.OFF; |
42 | 44 | import static org.openqa.selenium.chrome.ChromeDriverLogLevel.SEVERE; |
| 45 | +import static org.openqa.selenium.remote.CapabilityType.ACCEPT_INSECURE_CERTS; |
43 | 46 | import static org.openqa.selenium.remote.CapabilityType.TIMEOUTS; |
44 | 47 |
|
45 | 48 | @Tag("UnitTests") |
@@ -207,6 +210,60 @@ void mergingOptionsMergesExperimentalOptions() { |
207 | 210 | .containsEntry("opt3", "val3"); |
208 | 211 | } |
209 | 212 |
|
| 213 | + @Test |
| 214 | + void mergingOptionsWithMutableCapabilities() { |
| 215 | + File ext1 = TestUtilities.createTmpFile("ext1"); |
| 216 | + String ext1Encoded = Base64.getEncoder().encodeToString("ext1".getBytes()); |
| 217 | + String ext2 = Base64.getEncoder().encodeToString("ext2".getBytes()); |
| 218 | + |
| 219 | + MutableCapabilities one = new MutableCapabilities(); |
| 220 | + |
| 221 | + ChromeOptions options = new ChromeOptions(); |
| 222 | + options.addArguments("verbose"); |
| 223 | + options.addArguments("silent"); |
| 224 | + options.setExperimentalOption("opt1", "val1"); |
| 225 | + options.setExperimentalOption("opt2", "val4"); |
| 226 | + options.addExtensions(ext1); |
| 227 | + options.addEncodedExtensions(ext2); |
| 228 | + options.setAcceptInsecureCerts(true); |
| 229 | + File binary = TestUtilities.createTmpFile("binary"); |
| 230 | + options.setBinary(binary); |
| 231 | + |
| 232 | + one.setCapability(ChromeOptions.CAPABILITY, options); |
| 233 | + |
| 234 | + ChromeOptions two = new ChromeOptions(); |
| 235 | + two.addArguments("verbose"); |
| 236 | + two.setExperimentalOption("opt2", "val2"); |
| 237 | + two.setExperimentalOption("opt3", "val3"); |
| 238 | + two = two.merge(one); |
| 239 | + |
| 240 | + Map<String, Object> map = two.asMap(); |
| 241 | + |
| 242 | + assertThat(map).asInstanceOf(MAP) |
| 243 | + .extractingByKey(ChromeOptions.CAPABILITY).asInstanceOf(MAP) |
| 244 | + .extractingByKey("args").asInstanceOf(LIST) |
| 245 | + .containsExactly("verbose", "silent"); |
| 246 | + |
| 247 | + assertThat(map).asInstanceOf(MAP) |
| 248 | + .extractingByKey(ChromeOptions.CAPABILITY).asInstanceOf(MAP) |
| 249 | + .containsEntry("opt1", "val1") |
| 250 | + .containsEntry("opt2", "val4") |
| 251 | + .containsEntry("opt3", "val3"); |
| 252 | + |
| 253 | + assertThat(map).asInstanceOf(MAP) |
| 254 | + .extractingByKey(ACCEPT_INSECURE_CERTS).isExactlyInstanceOf(Boolean.class); |
| 255 | + |
| 256 | + assertThat(map).asInstanceOf(MAP) |
| 257 | + .extractingByKey(ChromeOptions.CAPABILITY).asInstanceOf(MAP) |
| 258 | + .extractingByKey("extensions").asInstanceOf(LIST) |
| 259 | + .containsExactly(ext1Encoded, ext2); |
| 260 | + |
| 261 | + assertThat(map).asInstanceOf(MAP) |
| 262 | + .extractingByKey(ChromeOptions.CAPABILITY).asInstanceOf(MAP) |
| 263 | + .extractingByKey("binary").asInstanceOf(STRING) |
| 264 | + .isEqualTo(binary.getPath()); |
| 265 | + } |
| 266 | + |
210 | 267 | @Test |
211 | 268 | void isW3CSafe() { |
212 | 269 | Map<String, Object> converted = new ChromeOptions() |
|
0 commit comments