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

1

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?

Capel answered 24/8, 2012 at 22:26 Comment(3)
Did you discover anything new about this?Foliolate
Just to make sure: you're using milliseconds for waitFor, right? I speak of experience ;) Also, don't forget about maxWait.Stenophyllous
"continuously polls for data from the server" -- if you have control over this, socket.io would be an excellent alternativeNelson
W
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);
Whig answered 7/3, 2013 at 20:36 Comment(1)
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 #37483391, that is not necessarily the case for all websites, unfortunately...Ennoble

© 2022 - 2024 — McMap. All rights reserved.