Last update: 11/08/2023.
The error looks like something like this: Failed to determine Chrome binary location. (Webdrivers::BrowserNotFound)
Under WSL, we are running the Linux version of Ruby, which won't be able to communicate via WebDriver with the Windows Chrome executable.
So, we need to change the default browser driver used by Capybara.
- Open the file
application_system_test_case.rb
inside your rails project, remove the configuration fordriven_by
and make sure to copy and pase the new driver configuration.
require "test_helper"
WINDOWS_HOST = `cat /etc/resolv.conf | grep nameserver | awk '{ print $2 }'`.strip
CHROMEDRIVER_URL = "http://#{WINDOWS_HOST}:9515/"
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :selenium_remote_chrome
Capybara.register_driver :selenium_remote_chrome do |app|
options = Selenium::WebDriver::Chrome::Options.new
options.add_argument('--start-maximized')
Capybara::Selenium::Driver.new(
app,
browser: :remote,
url: CHROMEDRIVER_URL,
options: options
)
end
Capybara.configure do |config|
# Match what's set for URL options in test.rb so we
# can test mailers that contain links.
config.server_host = 'localhost'
config.server_port = '3000'
end
end
- Go to ChromeDriver and download the last version of the driver. On my case I download de version 114.0.5735.90 for win32 => chromedriver_win32.zip
- Now, Rename it from chromedriver.exe to chromedriver. move it to a folder that you already have in the path system like c:/windows. You can also move it to another folder, but fon't forget to add it to the path system.
- Open a WSL console and try to run this:
chromedriver -v
. You should be able to use the driver from WSL
ChromeDriver 114.0.5735.90 (386bc09e8f4f2e025eddae123f36f6263096ae49-refs/branch-heads/5735@{#1052})
- Now it time to start the ChromeDriver. Run:
chromedriver --allowed-ips
Starting ChromeDriver 114.0.5735.90 (386bc09e8f4f2e025eddae123f36f6263096ae49-refs/branch-heads/5735@{#1052}) on port 9515
All remote connections are allowed. Use an allowlist instead!
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
At this point you should be able to run your system test rails test:system
.
- Add a Windows firewall rule to allow incoming connections for port 9515 (only if you need it).
- If the WINDOWS_HOST is wrong, you can replace this line by your local IP.
This instructions is a sumary of this discutions.