16

I've got a Web application that continuously polls for data from the server using Ajax requests. I would like to implement an integration test for it using zombie.js.

What I am trying to do is to wait until the Ajax poll loop receives data from the server. The data should be received after 20 seconds, so I use browser.wait(done, callback) to check if the data is there, and set waitFor to a maximum timeout of one minute.

However, browser.wait() always returns almost immediately, even if my done callback returns false.

In the zombie API documentation, I read the following about browser.wait():

... it can't wait forever, especially not for timers that may fire repeatedly (e.g. checking page state, long polling).

I guess that's the reason for the behavior I see, but I don't really understand what's going on. Why can't I wait for one minute until my poll loop receives data from the server? Why can't browser.wait() wait for timers that may fire repeatedly? What do I need to do to implement my test?

fstab
  • 992
  • 1
  • 11
  • 19

1 Answers1

3

Zombie.js will by default wait untill all the scripts on your page have loaded and executed if they are waiting for document ready.

If I understand you correctly, your script will not execute til after 20 seconds of document ready. In that case Zombie has a function which will let you evaluate javascript in the context of the browser, so you can kick off your ajax code quicker if it is on a timer, and you do not want to wait for it.

Look at browser.evaluate(expr)

Another option would be to simply use a normal JavaScript timeout to wait 20 seconds, and then look at the DOM for the changes you are expecting.

setTimeout(function(){
  browser.document.query("#interestingElement")
}, 20*1000);
ExxKA
  • 930
  • 6
  • 10
  • Just a note: it would have been really nice if Zombie really waited until all the scripts on the page have loaded, but as far as I can see on http://stackoverflow.com/questions/37482891/php-mink-zombie-handling-hanging-processes-after-a-fatal-exception, that is not necessarily the case for all websites, unfortunately... – sdbbs May 27 '16 at 12:15