Skip to content

Instantly share code, notes, and snippets.

@jnicklas
Created November 14, 2012 15:46
Show Gist options
  • Star 36 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save jnicklas/d8da686061f0a59ffdf7 to your computer and use it in GitHub Desktop.
Save jnicklas/d8da686061f0a59ffdf7 to your computer and use it in GitHub Desktop.
def wait_until
require "timeout"
Timeout.timeout(Capybara.default_wait_time) do
sleep(0.1) until value = yield
value
end
end
@vishnun
Copy link

vishnun commented Nov 20, 2013

Give an example usage as well.

@zacksiri
Copy link

zacksiri commented Feb 3, 2014

wait_until { page.should have_content("something") } @vishnun

@CoinAge
Copy link

CoinAge commented Aug 5, 2014

After some research, found that wait_until has been removed from capybara 2.0.

In my case, I was able to wait for the page to have label text using the below:
page.has_css?('classname')

Cheers!

@djanowski
Copy link

@zacksiri That's exactly when you should not use wait_until :)

See http://www.elabs.se/blog/53-why-wait_until-was-removed-from-capybara

@lisotton
Copy link

lisotton commented Jan 9, 2015

I liked the @CoinAge approach.

@camhine
Copy link

camhine commented Mar 4, 2015

This snippet of code has worked really well for us. Ideally we would use the waiting_rspec_matchers gem: https://github.com/abotalov/waiting_rspec_matchers. But we're on an older version of rspec so it isn't an option.

Here is the code we use to wait until the 'Content-Disposition' response header is present and then check that it is expected value.

wait_until { page.response_headers.include?('Content-Disposition') }
page.response_headers['Content-Disposition'].should include("expected value")

@localhostdotdev
Copy link

require 'timeout'

class SystemTestCase < ActionDispatch::SystemTestCase
  def wait_until(time, &block)
    Timeout.timeout(time) { sleep(0.01) until block.call }
  end
end

wait_until(5.seconds) { page.has_content?("something") }

worked well for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment