Skip to content

Commit 3f5b123

Browse files
committed
add test case for #1040
1 parent 8c16ead commit 3f5b123

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

src/test/java/org/htmlunit/WebClient2Test.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package org.htmlunit;
1616

1717
import static org.htmlunit.httpclient.HtmlUnitBrowserCompatCookieSpec.EMPTY_COOKIE_NAME;
18+
import static org.junit.jupiter.api.Assertions.assertThrows;
1819
import static org.junit.jupiter.api.Assertions.fail;
1920

2021
import java.io.File;
@@ -360,6 +361,52 @@ public void makeSureTheCurrentJobHasEndedBeforeReplaceWindowPage() throws Except
360361
// assertEquals(1, page.querySelectorAll("p").size());
361362
}
362363

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+
363410
/**
364411
* @throws Exception if something goes wrong
365412
*/

0 commit comments

Comments
 (0)