|
15 | 15 | package org.htmlunit; |
16 | 16 |
|
17 | 17 | import static org.htmlunit.httpclient.HtmlUnitBrowserCompatCookieSpec.EMPTY_COOKIE_NAME; |
| 18 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
18 | 19 | import static org.junit.jupiter.api.Assertions.fail; |
19 | 20 |
|
20 | 21 | import java.io.File; |
@@ -360,6 +361,52 @@ public void makeSureTheCurrentJobHasEndedBeforeReplaceWindowPage() throws Except |
360 | 361 | // assertEquals(1, page.querySelectorAll("p").size()); |
361 | 362 | } |
362 | 363 |
|
| 364 | + /** |
| 365 | + * @throws Exception if something goes wrong |
| 366 | + */ |
| 367 | + @Test |
| 368 | + @Alerts({"loadExtraContent started at Page 1", " loadExtraContent finished at Page 1"}) |
| 369 | + public void buttonClickReachesPageWithJScompileError() throws Exception { |
| 370 | + final String htmlStartPage = DOCTYPE_HTML |
| 371 | + + "<html>\n" |
| 372 | + + "<head>" |
| 373 | + + " <title>Page 1</title>\n" |
| 374 | + + "</head>\n" |
| 375 | + + "<body>\n" |
| 376 | + + " <form method='post' action='" + URL_SECOND + "'>\n" |
| 377 | + + " <input id='btnNext' type='submit' value='Next'>\n" |
| 378 | + + " </form>\n" |
| 379 | + + "</body>\n" |
| 380 | + + "</html>"; |
| 381 | + |
| 382 | + final String htmlSecondPage = DOCTYPE_HTML |
| 383 | + + "<html>\n" |
| 384 | + + "<head>" |
| 385 | + + " <title>Page 2</title>\n" |
| 386 | + + " <script>\n" |
| 387 | + + " this script does not compile!" |
| 388 | + + " </script>\n" |
| 389 | + + "</head>\n" |
| 390 | + + "<body>\n" |
| 391 | + + " <h1>Page2</h1>\n" |
| 392 | + + " <p>This is page 2</p>\n" |
| 393 | + + "</body>\n" |
| 394 | + + "</html>"; |
| 395 | + |
| 396 | + final WebClient client = getWebClient(); |
| 397 | + |
| 398 | + final MockWebConnection webConnection = getMockWebConnection(); |
| 399 | + client.setWebConnection(webConnection); |
| 400 | + |
| 401 | + webConnection.setDefaultResponse(htmlStartPage); |
| 402 | + webConnection.setResponse(URL_SECOND, htmlSecondPage); |
| 403 | + |
| 404 | + final HtmlPage page1 = client.getPage(URL_FIRST); |
| 405 | + assertEquals("Page 1", page1.getTitleText()); |
| 406 | + |
| 407 | + assertThrows(ScriptException.class, () -> page1.getElementById("btnNext").click()); |
| 408 | + } |
| 409 | + |
363 | 410 | /** |
364 | 411 | * @throws Exception if something goes wrong |
365 | 412 | */ |
|
0 commit comments