Skip to content

Instantly share code, notes, and snippets.

@danielberkompas
Created February 6, 2015 19:12
Show Gist options
  • Select an option

  • Save danielberkompas/f9cbc5f343ae59cc73f6 to your computer and use it in GitHub Desktop.

Select an option

Save danielberkompas/f9cbc5f343ae59cc73f6 to your computer and use it in GitHub Desktop.
Race Conditions in Capybara
def wait_for_ajax
Timeout.timeout(Capybara.default_wait_time) do
loop until finished_all_ajax_requests?
end
end
def finished_all_ajax_requests?
page.evaluate_script("jQuery.active").zero?
end
def wait_for(*locator)
raise ArgumentError if locator.blank?
begin
Timeout::timeout(10) do
until page.has_selector?(*locator)
sleep 0.25
end
end
rescue Timeout::Error
fail "'#{locator}' did not appear within 10 seconds"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment