Reputation: 1188
I'm getting the error above when trying to run Selenium on Heroku, RoR app.
I've added the buildpacks heroku-buildpack-google-chrome and heroku-buildpack-chromedriver
Then added the config variables
GOOGLE_CHROME_SHIM=/app/.apt/opt/google/chrome/chrome
GOOGLE_CHROME_BIN=/app/.apt/opt/google/chrome/chrome
And added this code on the capybara setup:
chrome_bin = ENV.fetch('GOOGLE_CHROME_SHIM', nil)
chrome_opts = chrome_bin ? { "chromeOptions" => { "binary" => chrome_bin } } : {}
Capybara.register_driver :chrome do |app| Capybara::Selenium::Driver.new(
app,
browser: :chrome,
desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome(chrome_opts), ) end
Capybara.javascript_driver = :chrome
As described on the chrome link: https://github.com/heroku/heroku-buildpack-google-chrome
Do I need to set up another variable for the location of the webdriver? If yes, how? and how do I assign it?
Thanks
Upvotes: 4
Views: 829
Reputation: 670
Was able to get this working on heroku rails app by using the following:
1) added the buildpacks heroku-buildpack-google-chrome and heroku-buildpack-chromedriver
2) set the driver in rails
options = Selenium::WebDriver::Chrome::Options.new
if Rails.env.production?
Selenium::WebDriver::Chrome.path = ENV["GOOGLE_CHROME_SHIM"]
end
options.add_argument("--headless")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--no-sandbox")
@driver = Selenium::WebDriver.for :chrome, options: options
No need to set any ENV variables on heroku as GOOGLE_CHROME_SHIM is set automatically by the webdriver build package.
Upvotes: 1