Confused about which Capybara methods will not wait

After reading @jferris excellent blog post on Capybara I wanted to dig in and figure out exactly which Capybara methods are not wait friendly.

The post calls out #all and #first (which simply wraps #all) as not waiting but by my reading of the #all docs & source it seems to use synchronize (source) the same way the find (docs & source method does. This seems to indicate that #all would also be wait friendly?

My question is whether this is an oversight in the blog post or (more likely) a gap in my understanding of how Capybara works?

Thanks in advance

Looking at the source, it’s definitely hard to tell what will wait and what won’t. Here are the basic rules:

  • All of these methods use synchronize, as you pointed out.
  • synchronize will retry if certain exceptions are raised.

So the trick is: when will all and find raise an exception so that synchronize retries?

When using find, the default behavior is to raise a retry-able exception if there are no results.

When using all, the default behavior is to raise only if a count is specified and not matched. This means that you can use all if you also specify enough count rules that you’re sure the page has loaded. The options are documented in Capybara’s docs, but in most cases, it will be enough to just use find.

I created a Gist which demonstrates this behavior.


Ah that explains it - thanks for taking the time to give such a detailed reply. I wish the Capybara readme contained this info - I will attempt a PR when I find some time.