-
Notifications
You must be signed in to change notification settings - Fork 110
Using with VCR or WebMock
Andrew edited this page Sep 6, 2023
·
14 revisions
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.
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.com
orgooglechromelabs.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:
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) }
# 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