Created
February 6, 2015 19:12
-
-
Save danielberkompas/f9cbc5f343ae59cc73f6 to your computer and use it in GitHub Desktop.
Race Conditions in Capybara
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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