Migrate from chromedriver-helper to Webdrivers

kinopyo avatar

kinopyo

chromedriver-helper is out of support as of 2019-03-31.
Webdrivers is recommended as the replacement. It's also included in the Rails 6 Gemfile.

Time for the switch! ⚡

Install Webdrivers gem

group :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.

WebMock.disable_net_connect!(
  allow_localhost: true,
  allow: "chromedriver.storage.googleapis.com"
)

Read more: https://github.com/titusfortner/webdrivers/issues/4

Set cache_time

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)
https://github.com/titusfortner/webdrivers#caching-drivers

I'm setting the cache to be 1 month:

# During the cache time, Webdrivers won't check to update Chrome.
Webdrivers.cache_time = 1.month.to_i

UPDATE:

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

That's it! ✨

kinopyo avatar
Written By

kinopyo

Indoor enthusiast, web developer, and former hardcore RTS gamer. #parenting
Published in Rails
Enjoyed the post?

Clap to support the author, help others find it, and make your opinion count.