Skip to content

Instantly share code, notes, and snippets.

@jerilevine
Last active November 7, 2016 21:07
Show Gist options
  • Select an option

  • Save jerilevine/cd3355fb2dcab6443ded1e61afaf951a to your computer and use it in GitHub Desktop.

Select an option

Save jerilevine/cd3355fb2dcab6443ded1e61afaf951a to your computer and use it in GitHub Desktop.
def reload_page
page.evaluate_script("window.location.reload()")
end
# Reload the page until either you hit the timeout, or the selector appears
# For use in places where the basic page.has_selector? wait won't work without
# reloading the whole page
#
# Accepts the same options as Capybara::Node::Matchers#has_selector?
def reload_until(*selector_args)
# If we passed a wait time, grab that and send the rest to page.has_selector?
wait_time = nil
if selector_args.last.is_a?(Hash)
wait_time = selector_args.last[:wait]
selector_args.last.delete(:wait)
end
if wait_time.nil?
wait_time = Capybara.default_max_wait_time
end
Timeout.timeout(wait_time) do
loop do
reload_page
break if page.has_selector? *selector_args
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment