|
1 | 1 | package dev.selenium.drivers;
|
2 | 2 |
|
3 | 3 | import dev.selenium.BaseTest;
|
| 4 | + |
| 5 | +import java.time.Duration; |
| 6 | +import java.time.temporal.ChronoUnit; |
| 7 | + |
4 | 8 | import org.junit.jupiter.api.Test;
|
| 9 | +import org.junit.jupiter.api.Assertions; |
5 | 10 | import org.openqa.selenium.PageLoadStrategy;
|
| 11 | +import org.openqa.selenium.UnexpectedAlertBehaviour; |
6 | 12 | import org.openqa.selenium.WebDriver;
|
7 | 13 | import org.openqa.selenium.chrome.ChromeOptions;
|
| 14 | +import org.openqa.selenium.remote.CapabilityType; |
8 | 15 | import org.openqa.selenium.chrome.ChromeDriver;
|
9 | 16 |
|
10 | 17 | public class OptionsTest extends BaseTest {
|
@@ -60,5 +67,107 @@ public void setAcceptInsecureCerts() {
|
60 | 67 | driver.quit();
|
61 | 68 | }
|
62 | 69 | }
|
| 70 | + |
| 71 | + @Test |
| 72 | + public void getBrowserName() { |
| 73 | + ChromeOptions chromeOptions = new ChromeOptions(); |
| 74 | + String name = chromeOptions.getBrowserName(); |
| 75 | + Assertions.assertFalse(name.isEmpty(), "Browser name should not be empty"); |
| 76 | + } |
| 77 | + |
| 78 | + @Test |
| 79 | + public void setBrowserVersion() { |
| 80 | + ChromeOptions chromeOptions = new ChromeOptions(); |
| 81 | + String version = "latest"; |
| 82 | + chromeOptions.setBrowserVersion(version); |
| 83 | + Assertions.assertEquals(version, chromeOptions.getBrowserVersion()); |
| 84 | + } |
| 85 | + |
| 86 | + @Test |
| 87 | + public void setPlatformName() { |
| 88 | + ChromeOptions chromeOptions = new ChromeOptions(); |
| 89 | + String platform = "OS X 10.6"; |
| 90 | + chromeOptions.setPlatformName(platform); |
| 91 | + Assertions.assertEquals(platform, chromeOptions.getPlatformName().toString()); |
| 92 | + } |
| 93 | + |
| 94 | + @Test |
| 95 | + public void setScriptTimeout() { |
| 96 | + ChromeOptions chromeOptions = new ChromeOptions(); |
| 97 | + Duration duration = Duration.of(5, ChronoUnit.SECONDS); |
| 98 | + chromeOptions.setScriptTimeout(duration); |
| 99 | + |
| 100 | + WebDriver driver = new ChromeDriver(chromeOptions); |
| 101 | + try { |
| 102 | + Duration timeout = driver.manage().timeouts().getScriptTimeout(); |
| 103 | + Assertions.assertEquals(timeout, duration, "The script timeout should be set to 5 seconds."); |
| 104 | + } finally { |
| 105 | + driver.quit(); |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | + @Test |
| 110 | + public void setPageLoadTimeout() { |
| 111 | + ChromeOptions chromeOptions = new ChromeOptions(); |
| 112 | + Duration duration = Duration.of(5, ChronoUnit.SECONDS); |
| 113 | + chromeOptions.setPageLoadTimeout(duration); |
| 114 | + |
| 115 | + WebDriver driver = new ChromeDriver(chromeOptions); |
| 116 | + try { |
| 117 | + Duration timeout = driver.manage().timeouts().getPageLoadTimeout(); |
| 118 | + Assertions.assertEquals(timeout, duration, "The page load timeout should be set to 5 seconds."); |
| 119 | + } finally { |
| 120 | + driver.quit(); |
| 121 | + } |
| 122 | + } |
| 123 | + |
| 124 | + @Test |
| 125 | + public void setImplicitWaitTimeout() { |
| 126 | + ChromeOptions chromeOptions = new ChromeOptions(); |
| 127 | + Duration duration = Duration.of(5, ChronoUnit.SECONDS); |
| 128 | + chromeOptions.setImplicitWaitTimeout(duration); |
| 129 | + |
| 130 | + WebDriver driver = new ChromeDriver(chromeOptions); |
| 131 | + try { |
| 132 | + Duration timeout = driver.manage().timeouts().getImplicitWaitTimeout(); |
| 133 | + Assertions.assertEquals(timeout, duration, "The implicit wait timeout should be set to 5 seconds."); |
| 134 | + } finally { |
| 135 | + driver.quit(); |
| 136 | + } |
| 137 | + } |
| 138 | + |
| 139 | + @Test |
| 140 | + public void setUnhandledPromptBehaviour() { |
| 141 | + ChromeOptions chromeOptions = new ChromeOptions(); |
| 142 | + chromeOptions.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.DISMISS_AND_NOTIFY); |
| 143 | + //verify the capability object is not null |
| 144 | + Object capabilityObject = chromeOptions.getCapability(CapabilityType.UNHANDLED_PROMPT_BEHAVIOUR); |
| 145 | + Assertions.assertNotNull(capabilityObject, "Capability UNHANDLED_PROMPT_BEHAVIOUR should not be null."); |
| 146 | + Assertions.assertEquals(capabilityObject.toString(), UnexpectedAlertBehaviour.DISMISS_AND_NOTIFY.toString()); |
| 147 | + } |
| 148 | + |
| 149 | + @Test |
| 150 | + public void setWindowRect() { |
| 151 | + ChromeOptions chromeOptions = new ChromeOptions(); |
| 152 | + chromeOptions.setCapability(CapabilityType.SET_WINDOW_RECT, true); |
| 153 | + //verify the capability object is not null |
| 154 | + Object capabilityObject = chromeOptions.getCapability(CapabilityType.SET_WINDOW_RECT); |
| 155 | + Assertions.assertNotNull(capabilityObject, "Capability SET_WINDOW_RECT should not be null."); |
| 156 | + |
| 157 | + Boolean capability = (Boolean) capabilityObject; |
| 158 | + Assertions.assertTrue(capability, "The capability SET_WINDOW_RECT should be set to true."); |
| 159 | + } |
| 160 | + |
| 161 | + @Test |
| 162 | + public void setStrictFileInteractability() { |
| 163 | + ChromeOptions chromeOptions = new ChromeOptions(); |
| 164 | + chromeOptions.setCapability(CapabilityType.STRICT_FILE_INTERACTABILITY, true); |
| 165 | + //verify the capability object is not null |
| 166 | + Object capabilityObject = chromeOptions.getCapability(CapabilityType.STRICT_FILE_INTERACTABILITY); |
| 167 | + Assertions.assertNotNull(capabilityObject, "Capability STRICT_FILE_INTERACTABILITY should not be null."); |
| 168 | + |
| 169 | + Boolean capability = (Boolean) capabilityObject; |
| 170 | + Assertions.assertTrue(capability, "The capability STRICT_FILE_INTERACTABILITY should be set to true."); |
| 171 | + } |
63 | 172 | }
|
64 | 173 |
|
0 commit comments