Miguel Parramón Teixidó

Wait for Javascript and AJAX changes in Capybara

· Miguel Parramón Teixidó · Blogger

𒈬: capybara, Ruby on Rails, testing

Recently I was having trouble with JS-enabled tests with Capybara on a Ruby on Rails app, when clicking stuff around and then asserting about content that was not on the page yet. I tried several solutions I found online, but either they were talking about wait_until, which is a method that’s not available in Capybara anymore, or they just didn’t work for me. Therefore, I decided to roll my own:

def wait_for
  Timeout.timeout(Capybara.default_wait_time) do
    loop until
      begin
        yield
      rescue MiniTest::Assertion
      end
  end
  yield
end

Read more »

𒁾 𒊕 𒅆𒁺 →