0

I have a web page where I have implemented a window.setTimeout in javascript. The thing is I am implementing a timer which pops up a message when that time has expired. This value is stored in the cookie.

So, when the page loads up, I configure the timer with the timeout value. So, even if the page is reloaded, the timer is created again on every page load.

Now, when I trying to test this through htmlunit(version - 2.15), each page of my is starting to load longer than the usual.

We have following configurations for the Webclient

webClient.getOptions().setTimeout(FIVE_MINUTES_IN_MILLIS);
webClient.waitForBackgroundJavaScript(NINETY_SECONDS);

I am guessing the way window.setTimeout is implemented in htmlunit is that it will wait for the timer to execute or waitForBackgroundJavaScript Timeout value(whichever occurs first). Hence, my htmlunit run is getting slowed as my timer is high(30 minutes) and each step of my htmlunit is waiting for 90 seconds.

How should I configure my htmlunit so that my script doesn't wait for that timer. Also, I need to have that waitForBackgroundJavaScript, otherwise, my ajax calls won't work.

Can somebody help here?

divinedragon
  • 5,105
  • 13
  • 50
  • 97
  • Did you try to use `webClient.waitForBackgroundJavaScript(NINETY_SECONDS);` only after the ajax calls, just after getting the page and before manipulating it (and not on the webClient initial configuration)? – haihui Aug 19 '16 at 07:44

2 Answers2

0

I do like this to wait for my ajax calls:

...
            HtmlPage page = (HtmlPage) webClient.getPage(url);
            HtmlInput details = null;
            int tries = 10;
            while (tries > 0 && details == null) {
                tries--;
                details = (HtmlInput) page.getElementById("PlaceHolderConteudo_grdListaResultado_btnDetalhar_0");
                synchronized (page) {
                    page.wait(1500);
                }
            }
...
pulu
  • 495
  • 1
  • 7
  • 16
0

You can implement your own wait based on the number of jobs still pending

JavaScriptJobManager tmpJobManager = myPage.getEnclosingWindow().getJobManager();
int tmpJobCount = tmpJobManager.getJobCount(jobFilter);

In this case you can provide your own JavaScriptJobFilter. So you are free to exclude some jobs from the list of jobs to wait for

RBRi
  • 2,704
  • 2
  • 11
  • 14