|
17 | 17 |
|
18 | 18 | package org.openqa.selenium.htmlunit; |
19 | 19 |
|
| 20 | +import static org.junit.Assert.fail; |
| 21 | + |
20 | 22 | import java.math.BigInteger; |
| 23 | +import java.net.InetAddress; |
21 | 24 | import java.util.HashMap; |
22 | 25 | import java.util.Map; |
23 | 26 |
|
|
26 | 29 | import org.openqa.selenium.By; |
27 | 30 | import org.openqa.selenium.JavascriptExecutor; |
28 | 31 | import org.openqa.selenium.WebDriver; |
| 32 | +import org.openqa.selenium.WebDriverException; |
29 | 33 | import org.openqa.selenium.WebElement; |
30 | 34 | import org.openqa.selenium.htmlunit.junit.BrowserRunner; |
31 | 35 | import org.openqa.selenium.htmlunit.junit.BrowserRunner.Alerts; |
@@ -188,4 +192,70 @@ public void executeScriptParamWebElement() throws Exception { |
188 | 192 | final String text = (String) ((JavascriptExecutor) webDriver).executeScript(js, webElement); |
189 | 193 | assertEquals("<div id=\"myDivId\">diff</div>", text); |
190 | 194 | } |
| 195 | + |
| 196 | + @Test |
| 197 | + public void getNotExistingUrl() throws Exception { |
| 198 | + final WebDriver webDriver = getWebDriver(); |
| 199 | + |
| 200 | + try { |
| 201 | + webDriver.get("https://getnotexistingurl_" + System.currentTimeMillis() + ".ace"); |
| 202 | + fail("WebDriverException expected"); |
| 203 | + } |
| 204 | + catch (final WebDriverException e) { |
| 205 | + // expected |
| 206 | + if (webDriver instanceof HtmlUnitDriver) { |
| 207 | + assertTrue(e.getMessage(), e.getMessage().startsWith("java.net.UnknownHostException: No such host is known (getnotexistingurl_")); |
| 208 | + } |
| 209 | + } |
| 210 | + } |
| 211 | + |
| 212 | + @Test |
| 213 | + @Alerts(DEFAULT = "Privacy error", |
| 214 | + FF = "self-signed.badssl.com", |
| 215 | + FF_ESR = "self-signed.badssl.com") |
| 216 | + @HtmlUnitNYI(CHROME = "self-signed.badssl.com", |
| 217 | + EDGE = "self-signed.badssl.com") |
| 218 | + public void getSslSelfSigned() throws Exception { |
| 219 | + final WebDriver webDriver = getWebDriver(); |
| 220 | + |
| 221 | + webDriver.get("https://self-signed.badssl.com"); |
| 222 | + assertEquals(getExpectedAlerts()[0], webDriver.getTitle()); |
| 223 | + assertEquals("https://self-signed.badssl.com/", webDriver.getCurrentUrl()); |
| 224 | + } |
| 225 | + |
| 226 | + @Test |
| 227 | + @Alerts(DEFAULT = "Privacy error", |
| 228 | + FF = "wrong.host.badssl.com", |
| 229 | + FF_ESR = "wrong.host.badssl.com") |
| 230 | + @HtmlUnitNYI(CHROME = "wrong.host.badssl.com", |
| 231 | + EDGE = "wrong.host.badssl.com") |
| 232 | + public void getSslWrongHost() throws Exception { |
| 233 | + final WebDriver webDriver = getWebDriver(); |
| 234 | + |
| 235 | + webDriver.get("https://wrong.host.badssl.com/"); |
| 236 | + assertEquals(getExpectedAlerts()[0], webDriver.getTitle()); |
| 237 | + assertEquals("https://wrong.host.badssl.com/", webDriver.getCurrentUrl()); |
| 238 | + } |
| 239 | + |
| 240 | + @Test |
| 241 | + @Alerts(DEFAULT = "revoked.badssl.com", |
| 242 | + FF = "WebDriverException", |
| 243 | + FF_ESR = "WebDriverException") |
| 244 | + @HtmlUnitNYI(FF = "revoked.badssl.com", |
| 245 | + FF_ESR = "revoked.badssl.com") |
| 246 | + public void getSslRevoked() throws Exception { |
| 247 | + final WebDriver webDriver = getWebDriver(); |
| 248 | + |
| 249 | + try { |
| 250 | + webDriver.get("https://revoked.badssl.com"); |
| 251 | + if ("WebDriverException".equals(getExpectedAlerts()[0])) { |
| 252 | + fail("WebDriverException expected"); |
| 253 | + } |
| 254 | + assertEquals(getExpectedAlerts()[0], webDriver.getTitle()); |
| 255 | + assertEquals("https://revoked.badssl.com/", webDriver.getCurrentUrl()); |
| 256 | + } |
| 257 | + catch (final WebDriverException e) { |
| 258 | + // expected |
| 259 | + } |
| 260 | + } |
191 | 261 | } |
0 commit comments