Home > database >  Best Practice to Maintain Matching Chromedriver Chrome Versions for Selenium/Ruby Script
Best Practice to Maintain Matching Chromedriver Chrome Versions for Selenium/Ruby Script

Time:09-23

I have a very simple Selenium/Ruby script, with the following key line excerpts:

#!/usr/bin/env ruby
...
require 'selenium-webdriver'
...
options = Selenium::WebDriver::Chrome::Options.new
...
driver = Selenium::WebDriver.for :chrome, options: options
...
driver.quit

Quite simply, it just uses the operating system's (Ubuntu Linux) default offerings for Chrome and Chromedriver.

Every now and then, the Chrome automatically updates, and the Chromedriver does not, causing the script to start failing when run:

This version of ChromeDriver only supports Chrome version XX
Current browser version is YY with binary path /usr/bin/chromium-browser

It is trivial for me to manually update Chromedriver each time, but it is annoying.

What is the best practice way to automagically keep Chromedriver updated to match Chrome?

CodePudding user response:

Generally in Python we use auto installer please see here, which is basically that auto install chromdriver against appropriate chrome browser version. We have the same functionality in Java-Selenium bindings as well using WebdriverManager.

Since you are asking for solely in ruby-Selenium bindings, I could find one Github repo, Please see here.

Run Selenium tests more easily with automatic installation and updates for all supported webdrivers.

  1. chromedriver
  2. geckodriver
  3. IEDriverServer
  4. msedgedriver

Works on macOS, Linux, Windows, and Windows Subsystem for Linux (WSL) v1 and v2. And do see the browser and OS specific notes at the bottom.

Usage

In your Gemfile:

gem 'webdrivers', '~> 4.0', require: false

In your project:

require 'webdrivers'

The drivers will now be automatically downloaded or updated when you launch a browser through Selenium.

  • Related