1

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)
yeniv
  • 93
  • 8

1 Answers1

1

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.

Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78
  • Thanks! How do I find if/where it's located in production? I've deployed on Heroku, if helpful. – yeniv Mar 11 '22 at 16:08
  • 1
    @yeniv On heroku make sure you've included the chrome buildpack - https://elements.heroku.com/buildpacks/heroku/heroku-buildpack-google-chrome - From those instructions one of either $GOOGLE_CHROME_BIN or $GOOGLE_CHROME_SHIM environment variables should have the needed location – Thomas Walpole Mar 11 '22 at 21:38
  • Thanks, Thomas! This solved the issue. – yeniv Mar 12 '22 at 13:21