Merge pull request #145 from opf/fix/rails3-cucumber-wait-for-ajax

merged anyhow. Maybe we want to add a sleep later but it is definitly not necessary.
pull/184/merge
Nils Kenneweg 12 years ago
commit 1ec8afbd00
  1. 10
      app/assets/javascripts/application.js
  2. 7
      features/step_definitions/web_steps.rb

@ -549,6 +549,16 @@ jQuery.viewportHeight = function() {
/* TODO: integrate with existing code and/or refactor */
jQuery(document).ready(function($) {
document.ajaxActive = false;
$(document).ajaxStart(function () {
document.ajaxActive = true;
});
$(document).ajaxStop(function () {
document.ajaxActive = false;
});
var propagateOpenClose = function () {
if ($(this).is(":visible")) {

@ -273,12 +273,14 @@ end
When /^I wait(?: (\d+) seconds)? for(?: the)? [Aa][Jj][Aa][Xx](?: requests?(?: to finish)?)?$/ do |timeout|
ajax_done = lambda do
page.evaluate_script(%Q{
is_done = false
while (!is_done) do
is_done = page.evaluate_script(%Q{
(function (){
var done = true;
if (window.jQuery) {
if (!window.jQuery.isReady || window.jQuery.active != 0) {
if (document.ajaxActive) {
done = false;
}
}
@ -292,6 +294,7 @@ When /^I wait(?: (\d+) seconds)? for(?: the)? [Aa][Jj][Aa][Xx](?: requests?(?: t
}())
}.gsub("\n", ''))
end
end
timeout = timeout.present? ?
timeout.to_f :

Loading…
Cancel
Save