|
19 | 19 |
|
20 | 20 | import org.junit.Test;
|
21 | 21 | import org.junit.experimental.categories.Category;
|
| 22 | +import org.openqa.selenium.PageLoadStrategy; |
| 23 | +import org.openqa.selenium.UnexpectedAlertBehaviour; |
22 | 24 | import org.openqa.selenium.remote.AcceptedW3CCapabilityKeys;
|
23 | 25 | import org.openqa.selenium.testing.TestUtilities;
|
24 | 26 | import org.openqa.selenium.testing.UnitTests;
|
25 | 27 |
|
26 | 28 | import java.io.File;
|
| 29 | +import java.time.Duration; |
27 | 30 | import java.util.Base64;
|
| 31 | +import java.util.HashMap; |
28 | 32 | import java.util.List;
|
29 | 33 | import java.util.Map;
|
30 | 34 | import java.util.Set;
|
31 | 35 | import java.util.function.Predicate;
|
32 |
| -import java.util.stream.Collectors; |
33 | 36 |
|
34 | 37 | import static java.util.stream.Collectors.toSet;
|
35 | 38 | import static org.assertj.core.api.Assertions.assertThat;
|
|
38 | 41 | import static org.assertj.core.api.InstanceOfAssertFactories.MAP;
|
39 | 42 | import static org.openqa.selenium.chrome.ChromeDriverLogLevel.OFF;
|
40 | 43 | import static org.openqa.selenium.chrome.ChromeDriverLogLevel.SEVERE;
|
| 44 | +import static org.openqa.selenium.remote.CapabilityType.TIMEOUTS; |
41 | 45 |
|
42 | 46 | @Category(UnitTests.class)
|
43 | 47 | public class ChromeOptionsTest {
|
@@ -67,6 +71,66 @@ public void canBuildLogLevelFromStringRepresentation() {
|
67 | 71 | assertThat(ChromeDriverLogLevel.fromString("SEVERE")).isEqualTo(SEVERE);
|
68 | 72 | }
|
69 | 73 |
|
| 74 | + @Test |
| 75 | + public void canAddW3CCompliantOptions() { |
| 76 | + ChromeOptions chromeOptions = new ChromeOptions(); |
| 77 | + chromeOptions.setBrowserVersion("99") |
| 78 | + .setPlatformName("9 3/4") |
| 79 | + .setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.IGNORE) |
| 80 | + .setAcceptInsecureCerts(true) |
| 81 | + .setPageLoadStrategy(PageLoadStrategy.EAGER) |
| 82 | + .setStrictFileInteractability(true) |
| 83 | + .setImplicitWaitTimeout(Duration.ofSeconds(1)) |
| 84 | + .setPageLoadTimeout(Duration.ofSeconds(2)) |
| 85 | + .setScriptTimeout(Duration.ofSeconds(3)); |
| 86 | + |
| 87 | + Map<String, Object> mappedOptions = chromeOptions.asMap(); |
| 88 | + assertThat(mappedOptions.get("browserName")).isEqualTo("chrome"); |
| 89 | + assertThat(mappedOptions.get("browserVersion")).isEqualTo("99"); |
| 90 | + assertThat(mappedOptions.get("platformName")).isEqualTo("9 3/4"); |
| 91 | + assertThat(mappedOptions.get("unhandledPromptBehavior").toString()).isEqualTo("ignore"); |
| 92 | + assertThat(mappedOptions.get("acceptInsecureCerts")).isEqualTo(true); |
| 93 | + assertThat(mappedOptions.get("pageLoadStrategy").toString()).isEqualTo("eager"); |
| 94 | + assertThat(mappedOptions.get("strictFileInteractability")).isEqualTo(true); |
| 95 | + |
| 96 | + Map<String, Long> expectedTimeouts = new HashMap<>(); |
| 97 | + expectedTimeouts.put("implicit", 1000L); |
| 98 | + expectedTimeouts.put("pageLoad", 2000L); |
| 99 | + expectedTimeouts.put("script", 3000L); |
| 100 | + |
| 101 | + assertThat(expectedTimeouts).isEqualTo(mappedOptions.get("timeouts")); |
| 102 | + } |
| 103 | + |
| 104 | + @Test |
| 105 | + public void canAddSequentialTimeouts() { |
| 106 | + ChromeOptions chromeOptions = new ChromeOptions(); |
| 107 | + chromeOptions.setImplicitWaitTimeout(Duration.ofSeconds(1)); |
| 108 | + |
| 109 | + Map<String, Object> mappedOptions = chromeOptions.asMap(); |
| 110 | + Map<String, Long> expectedTimeouts = new HashMap<>(); |
| 111 | + |
| 112 | + expectedTimeouts.put("implicit", 1000L); |
| 113 | + assertThat(expectedTimeouts).isEqualTo(mappedOptions.get("timeouts")); |
| 114 | + |
| 115 | + chromeOptions.setPageLoadTimeout(Duration.ofSeconds(2)); |
| 116 | + expectedTimeouts.put("pageLoad", 2000L); |
| 117 | + Map<String, Object> mappedOptions2 = chromeOptions.asMap(); |
| 118 | + assertThat(expectedTimeouts).isEqualTo(mappedOptions2.get("timeouts")); |
| 119 | + } |
| 120 | + |
| 121 | + @Test |
| 122 | + public void mixAddingTimeoutsCapsAndSetter() { |
| 123 | + ChromeOptions chromeOptions = new ChromeOptions(); |
| 124 | + chromeOptions.setCapability(TIMEOUTS, Map.of("implicit", 1000)); |
| 125 | + chromeOptions.setPageLoadTimeout(Duration.ofSeconds(2)); |
| 126 | + |
| 127 | + Map<String, Number> expectedTimeouts = new HashMap<>(); |
| 128 | + expectedTimeouts.put("implicit", 1000); |
| 129 | + expectedTimeouts.put("pageLoad", 2000L); |
| 130 | + |
| 131 | + assertThat(chromeOptions.asMap().get("timeouts")).isEqualTo(expectedTimeouts); |
| 132 | + } |
| 133 | + |
70 | 134 | @Test
|
71 | 135 | public void mergingOptionsMergesArguments() {
|
72 | 136 | ChromeOptions one = new ChromeOptions().addArguments("verbose");
|
|
0 commit comments