Time for the switch! ️
Install Webdrivers gem
Gemfilegroup :test do gem "capybara", "~> 3.0" gem "selenium-webdriver" - gem "chromedriver-helper" + gem "webdrivers" end
bundle install. If you're using Rails then it'll be automatically loaded via Railtie.
For non-rails project, you'll need to
require 'webdrivers' manually.
Whitelist in WebMock
Webdrivers will check the latest supported driver and automatically download it unless you set a specific version. This is probably the major difference.
If you're using WebMock, you'll need to whitelist the url so Webdrivers can download the driver, otherwise you'll get this error:
WebMock::NetConnectNotAllowedError: Real HTTP connections are disabled. Unregistered request: GET https://chromedriver.storage.googleapis.com/LATEST_RELEASE_74.0.3729
Let's whitelist the host.
spec/support/webmock.rbWebMock.disable_net_connect!( allow_localhost: true, allow: "chromedriver.storage.googleapis.com" )
As of the time of writing, the latest version of Webdrivers is
3.9.2 and it'd warn of upgrading to the upcoming v4 default:
WARN Webdrivers Driver caching is turned off in this version, but will be enabled by default in 4.x. Set the value with `Webdrivers#cache_time=` in seconds
The default in 3.9 is zero, and the default for 4.x will be 24 hours (86,400 seconds)
I'm setting the cache to be 1 month:
Thanks to @titusfortner, the author of the gem(!), who recommended a max-of-one-day cache and shared one insightful detail of how it works !
I wouldn't recommend setting the cache to more than a day. You should be able to afford to make one network call per day on a system to make sure you have the latest bug fixes in place for your driver. Note that the cache will be ignored if Chrome is updated a major version.
Tip: You can verify the behavior by setting the logger level to debug as below:
Webdrivers.logger.level = :debug
Then when you run your spec, you can tell from the stdout whether it's downloading latest Chrome or not.
Browser executable: /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome making System call: /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version Browser version: Google Chrome 74.0.3729.157 Latest version available: 74.0.3729.6 A working webdriver version is already on the system