2

How do I configure Heroku CI to run System tests?

This is my app.json, where I included what I thought would be the necessary buildpacks:

    {
  "environments": {
    "test": {
      "scripts": {
        "test-setup": "bin/rails assets:precompile",
        "test": "bin/rails test:system"
      },
      "addons":[
        "heroku-postgresql:in-dyno"
      ],
      "buildpacks": [
        { "url": "https://github.com/heroku/heroku-buildpack-google-chrome" },
        { "url": "heroku/nodejs" },
        { "url": "heroku/ruby"}
      ]
    }
  }
}

But when I deploy, I get the following error:

-----> Running test command `bin/rails test:system`...
rails aborted!
Webdrivers::BrowserNotFound: Failed to find Chrome binary.

I suspect I am missing something very basic....

I running Rails 6.0.1 and Ruby 2.6.3.

Carson Cole
  • 4,183
  • 6
  • 25
  • 35

1 Answers1

3

Did you setup your webdriver correctly to find the correct binary as mentioned on the official UAT wiki page of heroku?

  1. Add gem 'webdrivers' to your Gemfile.

  2. Add the following code snippet to your test_helper.rb (as stated on heroku buildback wiki and on webdrivers wiki):

require 'webdrivers' # Make sure webdrivers are loaded.

chrome_bin = ENV['GOOGLE_CHROME_SHIM'] if ENV['GOOGLE_CHROME_SHIM'].present?

chrome_capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
  chromeOptions: {
    # You may want to use a different args
    args: %w[headless disable-gpu window-size=1400x1400],
    binary: chrome_bin
  }
)

Capybara.register_driver :heroku_chrome do |app|
  Capybara::Selenium::Driver.new(app, browser: :chrome, desired_capabilities: chrome_capabilities)
end
  1. Afterwards tell your system test to use your custom chrome driver by adding it to your application_system_test_case.rb.
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
  driven_by :heroku_chrome
end
Flori
  • 671
  • 7
  • 12