开发者

How to make HtmlUnit's WebClient accelerate execution of javascript to be triggered by window.setTimeout?

I am using the Java library 开发者_如何学GoHtmlUnit to create a regression test suite for a web app.

I have an "onload" handler hooked in the body of pages of the app to redirect to a timeout page after the session would have expired. The handler is some JavaScript of the form:

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

I would like to test that the redirect will eventually be fired when the time arrives, but the closest thing I can find is to actually wait the entire duration of the time (say 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 trick the script execution engine into behaving as if that much time has passed, without actually having to wait minutes or hours "real time" for a test suite to be run.

Ideally, one could tell the engine/client/interpreter that X milliseconds had passed (to emulate the wait), or perhaps to set some kind of "time dilation" factor and poll the page to see how it is being updated.


I don't think you can do that easily. The only way I can see it possible would be by mocking the Rhino method that handles the settimeout in you tests... Perhaps with a framework like Mockito... But that's not what you want as if you want to test the effectiveness of the redirection of the page, you test the amount of time it takes to be redirected

cheers

grooveek

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜