Capybara increase max allowed page load time

1 min


645
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.

Solution:

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 = Selenium::WebDriver::Remote::Http::Default.new
  client.timeout = 120
  Capybara::Selenium::Driver.new(app, http_client: client)
end

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!

645
1 share, 645 points

What's Your Reaction?

cute cute
1
cute
scary scary
0
scary
wtf wtf
0
wtf
geek geek
0
geek
WIN WIN
0
WIN
Love Love
0
Love
OMG OMG
0
OMG
Angry Angry
0
Angry
Lol Lol
0
Lol
Test engineer

0 Comments

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

Choose A Format
Trivia quiz
Story