Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I force Selenium to run tests only after $(document).ready() has completed?

Our site does a lot of JavaScript/jQuery work in the $(document).ready() function, setting up buttons, loading content via ajax, etc. Selenium waits until the DOM is loaded, but then proceeds to test before .ready() has completed.

A partial solution seems to be using a check to see if the browser has pending ajax requests:

selenium.browserbot.getCurrentWindow().jQuery.active == 0

However that doesn't ensure that we aren't still setting up bindings for buttons and things.

Any help will be greatly appreciated. The current 'best' suggestion is adding an element to the page at the end of the .ready() method, which Selenium can catch as a signal to start working, but the idea of adding code like this for testing purposes seems sketchy at best.

like image 555
David Smith Avatar asked Jan 14 '11 19:01

David Smith


1 Answers

I believe you can use the window load check. Try this:

$(window).load(function(){  
  selenium.browserbot.getCurrentWindow().jQuery.active == 0 
});  
like image 113
Michael Irigoyen Avatar answered Oct 21 '22 08:10

Michael Irigoyen