admin管理员组文章数量:1426799
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 pleted.
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.
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 pleted.
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.
Share Improve this question asked Jan 14, 2011 at 19:22 David SmithDavid Smith 39.9k11 gold badges47 silver badges61 bronze badges2 Answers
Reset to default 3I believe you can use the window load check. Try this:
$(window).load(function(){
selenium.browserbot.getCurrentWindow().jQuery.active == 0
});
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.
I don't personally think that modifying your code to improve testability is a bad thing. If you really would rather not pollute your production pages then use some templating tool like PHP to output the code only in development/debug mode.
Also, you don't need to use the DOM for this. Selenium has access to the the full javascript context in the page so you can just use a global variable as a flag. Maybe something that is unlikely to be used by others like SELENIUM_PAGE_FULLY_READY
then have Selenium check for its existence.
版权声明:本文标题:javascript - How can I force Selenium to run tests only after $(document).ready() has completed? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745485453a2660361.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论