5454import org .htmlunit .util .NameValuePair ;
5555import org .htmlunit .util .UrlUtils ;
5656import org .htmlunit .xml .XmlPage ;
57+ import org .junit .jupiter .api .Assertions ;
5758import org .junit .jupiter .api .Test ;
5859
5960/**
@@ -1700,8 +1701,6 @@ public void javaScriptTimeout() throws Exception {
17001701 client .setJavaScriptTimeout (timeout );
17011702
17021703 try {
1703- client .getOptions ().setThrowExceptionOnScriptError (false );
1704-
17051704 final String content = DOCTYPE_HTML + "<html><body><script>while(1) {}</script></body></html>" ;
17061705 final MockWebConnection webConnection = new MockWebConnection ();
17071706 webConnection .setDefaultResponse (content );
@@ -1727,7 +1726,19 @@ public void run() {
17271726 runner .interrupt ();
17281727 fail ("Script was still running after timeout" );
17291728 }
1730- assertNull (exceptions [0 ]);
1729+
1730+ Assertions .assertTrue (exceptions [0 ] instanceof RuntimeException , exceptions [0 ].getMessage ());
1731+ final Throwable cause = exceptions [0 ].getCause ();
1732+ String msg = cause .getMessage ();
1733+ Assertions .assertTrue (cause .getMessage ().startsWith (
1734+ "Javascript execution takes too long (allowed: 2000ms, already elapsed: " ), cause .getMessage ());
1735+
1736+ msg = msg .substring (msg .indexOf ("already elapsed: " ) + 17 );
1737+ msg = msg .substring (0 , msg .indexOf ("ms" ));
1738+ final long execTime = Long .parseLong (msg );
1739+
1740+ Assertions .assertTrue (execTime >= timeout , "execTime: " + execTime );
1741+ Assertions .assertTrue (execTime < (timeout + 2 ), "execTime: " + execTime );
17311742 }
17321743 finally {
17331744 client .setJavaScriptTimeout (oldTimeout );
0 commit comments