Search code examples
ruby-on-railsrubycapybaracuprite

Rails capybara Cliver::Dependency::NotFound in production


I'm attempting to run Capybara in production in a scheduled Sidekiq task in my Rails app. It works locally (as it was designed to), but when deployed I run into a Cliver::Dependency::NotFound error.

Do you have any ideas on how I can get this working?

require 'capybara'
require 'capybara/cuprite'

Capybara.javascript_driver = :cuprite
Capybara.enable_aria_label = true
Capybara.register_driver(:cuprite) do |app|
  Capybara::Cuprite::Driver.new(app, {
    js_errors: false,
    headless: true,
    timeout: 500,
    slowmo: 0.05
  })
end

@session = Capybara::Session.new(:cuprite)
@session.visit('www.some-url-goes-here.com')

This is the error that's triggered when visiting any URL.

/app/vendor/bundle/ruby/3.0.0/gems/ferrum-0.11/lib/ferrum/browser/command.rb:32:in `initialize': Could not find an executable for the browser. Try to make it available on the PATH or set environment variable for example BROWSER_PATH="/usr/bin/chrome" (Cliver::Dependency::NotFound)

Solution

  • You need to tell Cuprite where the Chrome browser binary is located on your production machine. It searches common locations, so in your production env it’s either not installed or installed in a non-default location.