Skip to content

Instantly share code, notes, and snippets.

@natritmeyer
Created February 24, 2012 11:04
Show Gist options
  • Save natritmeyer/1900170 to your computer and use it in GitHub Desktop.
Save natritmeyer/1900170 to your computer and use it in GitHub Desktop.
Fix for ajax problems in tests
module AjaxWaiter
def wait_for_ajax
wait_until { page.evaluate_script("jQuery.active") == 0 }
end
end
World(AjaxWaiter)
Given /^I do something which kicks off an ajax transaction$/ do
click_link 'whatever'
#at this point the test used to die, but now it doesn't because we have...
wait_for_ajax
#the test continues - woohoo!
click_link 'something_else' #this line originally caused the test to die because it tried to execute whilst the browser was still talking with the server
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment