Recently at work, I spent over a day trying to get one failing test to pass. I tried everything in the code, but no dice. Finally, I realized that the problem wasn’t with my code – it was with the way Capybara works. I want to save you the time I lost, so let’s get to it.
Capybara, to quote its creator Jonas Nicklas, “is ridiculously good at waiting for content.” It knows that when it’s told to find something on the page, or click a link, and it’s not there, don’t sweat it – just keep trying until a default timeout (
Capybara.default_wait_time) is hit. When, and only when, that timeout is hit, Capybara will give you an
This works great for most use cases. However, sometimes it just isn’t enough. Let’s illustrate with a real-world example.