How to get HtmlUnit WebClient to speed up javascript execution to run window.setTimeout?

I am using the HtmlUnit Java library to create a set of regression tests for a web application.

I have an "onload" handler hooked in the body of the application pages to redirect to the timeout page after the session expires. A handler is some kind of JavaScript form:

window.setTimeout( function() { window.location = 'timout.html'; }, 3600000);

I would like to verify that the redirect will eventually start when the time comes, but the closest thing I can find is actually to wait for the entire duration of the time (for example, an hour in the example above), as suggested by the Java sample below:

WebClient webClient = new WebClient(); ... webClient.waitForBackgroundJavaScript( 3600000);

I would like to know if it is possible to fool the script execution mechanism to behave as if a lot of time had passed, without having to wait for minutes or hours of "real time" to run the test suite.

Ideally, you can say that the engine / client / interpreter skipped X milliseconds (to mimic the expectation) or, perhaps, set some kind of “time dilation” factor and poll the page to see how it refreshes.

+4
source share
1 answer

I do not think you can do this easily. The only way I can see this is to mock the Rhino method, which handles the setup in tests ... Maybe with a card like Mockito ... But that's not what you want, as if you wanted to test page redirection efficiency, you check the amount of time it takes to redirect.

greetings

grooveek

+1
source