Using with VCR or WebMock - titusfortner/webdrivers GitHub Wiki
Update
The solutions here are not working for webdrivers 5.3 because chrome now has 2 "base_url" values, and for chromedriver 115+ it is looking for googlechromelabs.github.io. You will need to add this yourself, or switch to Selenium 4.11 and set the mocks on the DriverFinder class.
Description
You may get this error when using webdrivers with VCR or WebMock gem:
Selenium::WebDriver::Error::WebDriverError: unable to connect to chromedriver
This is because the request to the following download URLs is being blocked and the driver fails to download:
- Chromedriver -
chromedriver.storage.googleapis.comorgooglechromelabs.github.io - Geckodriver -
github.com/mozilla/geckodriver/releases - IEDriverServer -
selenium-release.storage.googleapis.com - MicrosoftWebDriver -
developer.microsoft.com/en-us/microsoft-edge/tools/webdriver
Use the gem specific code below to grab a list of these URLs and add them to the list of ignore_hosts or allowed_sites to unblock them:
VCR
require 'uri'
# With activesupport gem
driver_hosts = Webdrivers::Common.subclasses.map { |driver| URI(driver.base_url).host }
# Without activesupport gem
driver_hosts = (ObjectSpace.each_object(Webdrivers::Common.singleton_class).to_a - [Webdrivers::Common]).map { |driver| URI(driver.base_url).host }
VCR.configure { |config| config.ignore_hosts(*driver_hosts) }
WebMock
# With activesupport gem
driver_urls = Webdrivers::Common.subclasses.map(&:base_url)
# Without activesupport gem
driver_urls = (ObjectSpace.each_object(Webdrivers::Common.singleton_class).to_a - [Webdrivers::Common]).map(&:base_url)
driver_urls << /geckodriver/
# We've seen [a redirect](https://github.com/titusfortner/webdrivers/issues/204) to this domain
driver_urls += ["github-releases.githubusercontent.com"] # this is added
WebMock.disable_net_connect!(allow_localhost: true, allow: driver_urls)
Sources
https://github.com/titusfortner/webdrivers/issues/204
https://github.com/titusfortner/webdrivers/issues/109