|
21 | 21 | import java.util.Iterator; |
22 | 22 | import java.util.List; |
23 | 23 |
|
| 24 | +import org.htmlunit.corejs.javascript.JavaScriptException; |
24 | 25 | import org.junit.Assert; |
25 | 26 | import org.junit.Test; |
26 | 27 | import org.junit.runner.RunWith; |
27 | 28 | import org.openqa.selenium.By; |
| 29 | +import org.openqa.selenium.JavascriptException; |
28 | 30 | import org.openqa.selenium.JavascriptExecutor; |
29 | 31 | import org.openqa.selenium.ScriptTimeoutException; |
30 | 32 | import org.openqa.selenium.WebDriver; |
@@ -202,13 +204,27 @@ public void shouldDetectPageLoadsWhileWaitingOnAnAsyncScriptAndReturnAnError() t |
202 | 204 | getMockWebConnection().setResponse(URL_SECOND, "<html><body></body></html>"); |
203 | 205 |
|
204 | 206 | final WebDriver driver = loadPage2("<html><body></body></html>"); |
205 | | - driver.manage().timeouts().scriptTimeout(Duration.ofMillis(100)); |
| 207 | + // driver.manage().timeouts().scriptTimeout(Duration.ofMillis(100)); |
206 | 208 |
|
207 | 209 | final JavascriptExecutor executor = (JavascriptExecutor) driver; |
208 | | - // TODO real FF creates JavascriptException |
| 210 | + // TODO real FF creates JavascriptException, Chrome/Edge ScriptTimeoutException |
| 211 | + /* |
209 | 212 | Assert.assertThrows( |
210 | 213 | ScriptTimeoutException.class, |
211 | 214 | () -> executor.executeAsyncScript("window.location = '" + URL_SECOND + "';")); |
| 215 | + */ |
| 216 | + final Throwable t = Assert.assertThrows( |
| 217 | + Throwable.class, |
| 218 | + () -> executor.executeAsyncScript("window.location = '" + URL_SECOND + "';")); |
| 219 | + |
| 220 | + assertTrue(t instanceof ScriptTimeoutException || t instanceof JavascriptException); |
| 221 | + |
| 222 | + if (t instanceof ScriptTimeoutException) { |
| 223 | + assertTrue(t.getMessage().startsWith("script timeout")); |
| 224 | + } |
| 225 | + else if (t instanceof JavaScriptException) { |
| 226 | + assertEquals("Document was unloaded", t.getMessage()); |
| 227 | + } |
212 | 228 | } |
213 | 229 |
|
214 | 230 | @Test |
@@ -261,7 +277,7 @@ public void shouldCatchErrorsWithMessageAndStacktraceWhenExecutingInitialScript( |
261 | 277 | assertTrue(ex.getMessage().contains("errormessage")); |
262 | 278 |
|
263 | 279 | final Throwable rootCause = ex.getCause(); |
264 | | - assertTrue(result instanceof Throwable); |
| 280 | + assertTrue(rootCause instanceof Throwable); |
265 | 281 | // does not work with real browsers because root cause is null |
266 | 282 | assertTrue(rootCause.getMessage().contains("errormessage")); |
267 | 283 |
|
|
0 commit comments