Created
August 8, 2019 14:18
-
-
Save vhorb/e64904ecd33d722958e98d423f83637f to your computer and use it in GitHub Desktop.
Custom waits for selenium
This file contains 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
module WaitHelper | |
def wait_for_ajax | |
Timeout.timeout(60) do | |
sleep(0.7) until Capybara.page.evaluate_script('jQuery.active').zero? | |
end | |
rescue Selenium::WebDriver::Error::UnknownError | |
sleep(1) | |
end | |
def selenium_wait(seconds = 60) | |
Selenium::WebDriver::Wait.new(:timeout => seconds).until {yield} | |
end | |
def wait_state_ready | |
selenium_wait {execute_script("return document.readyState;") == "complete"} | |
end | |
def waiting | |
wait_state_ready | |
wait_for_ajax | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment