Capybara increase max allowed page load time

1 share, 645 points
Capybara increase max allowed page load time
Capybara increase max allowed page load time

Capybara increase max allowed page load time

Sometimes you might have a page that loads in over a minute and assuming this is the expected behaviour and wont change. So what we can do in order to fix this because your tests will fail because of the slow pages or slow environment. But there is a solution to make Capybara increase max allowed page load time on the client.


Selenium has a lot of different timeout settings, some of which can be changed at runtime, others which have to be set when the driver is initialize. You are most likely running into the Http::Default timeout which defaults to 60 seconds. You can override this by passing your own instance into the Selenium driver as http_client

Capybara.register_driver :slow_selenium do |app|
  client =
  client.timeout = 120, http_client: client)

and then use the :slow_selenium driver for tests which will take over a minute to load the page

Just to clarify for anyone’s future reference – you can tell Capybara to use the new driver for some of your specs by adding the driver: :slow_selenium tag

The reason of this solution is to not have a big value for Capybara.default_wait_time.

You had better not set much time to Capybara_default_wait_time.


For example, if you set 10 seconds to Capybara.default_wait_time when you want to check the element dose not exist. Test time can be long. Because Capybara wait to check the element dose not exist in each test.

Capybara.default_wait_time = 10

expect(page).to have_no_selector(:css, "p a#doesnotexist") # wait 10 seconds

If you need more than 3 seconds(default value in Capybara.default_wait_time) to wait to check you can set wait option to find instead.

expect(page).to have_selector(:css, "invalid elment", wait: 3)

If you want to find out more about wait times you can consult the api documentation .

Hope you find this useful in your project.

Happy Testing!

Like it? Share with your friends!

1 share, 645 points
Test engineer


Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.