Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use browser.wait() in zombie.js?

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?

like image 414
fabstab Avatar asked Aug 24 '12 22:08

fabstab


1 Answers

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);
like image 72
ExxKA Avatar answered Oct 05 '22 01:10

ExxKA