Skip to content

Instantly share code, notes, and snippets.

@vhorb
Created August 8, 2019 14:18
Show Gist options
  • Save vhorb/e64904ecd33d722958e98d423f83637f to your computer and use it in GitHub Desktop.
Save vhorb/e64904ecd33d722958e98d423f83637f to your computer and use it in GitHub Desktop.
Custom waits for selenium
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