DEV Community

Tomoyuki Kashiro
Tomoyuki Kashiro

Posted on • Originally published at blog.tomoyukikashiro.me on

2 1

Things to be aware of when change Capybara default_wait_time

This post was originally published at Things to be aware of when change Capybara default_wait_time

About Capybara.default_wait_time

According to api document

find will wait for a set amount of time and continuously retry finding the element until either the element is found or the time expires. The length of time find will wait is controlled through Capybara.default_wait_time and defaults to 2 seconds.

ATTENTION

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.

# in rspec.rb
Capybara.default_wait_time = 10

# in feature test
expect(page).to have_no_selector(:css, "p a#doesnotexist") # wait 10 seconds
Enter fullscreen mode Exit fullscreen mode

Solution

If you need more than 2 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, "p a#doesnotexist", wait: 3)
Enter fullscreen mode Exit fullscreen mode

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay