I have a Ruby code that does this:
browser = Watir::Browser.new(:chrome, switches: switches, headless: true)
browser.goto(....)
When I run the code on Heroku I get
Selenium::WebDriver::Error::WebDriverError: Unable to find chromedriver. Please download the server from http://chromedriver.storage.googleapis.com/index.html and place it somewhere on your PATH. More info at https://github
.com/SeleniumHQ/selenium/wiki/ChromeDriver.
I've seen posts like Heroku: unable to connect to chromedriver 127.0.0.1:9515 when using Watir/Selenium
but I don't know how to properly configure the buildpacks.
I've tried with:
heroku buildpacks:set https://github.com/heroku/heroku-buildpack-google-chrome
heroku buildpacks:set https://github.com/heroku/heroku-buildpack-chromedriver
but then when I try to push the changes to Heroku I get:
Error Plugin: chromedriver: files attribute must be specified in /Users/leticia/.local/share/heroku/node_modules/chromedriver/package.json
Can someone give me a step by step on how to set the necessary buildpacks to make the Watir gem work in Heroku?
Thank you
Update:
I've required 'webdrivers' and now I'm getting Selenium::WebDriver::Error::WebDriverError: unable to connect to chromedriver 127.0.0.1:9515
.
I've tried configuring the env vars to:
ENV['GOOGLE_CHROME_BIN'] = "/app/.apt/opt/google/chrome/chrome"
ENV['GOOGLE_CHROME_SHIM'] = "/app/.apt/usr/bin/google-chrome-stable"
and doing this:
options = Selenium::WebDriver::Chrome::Options.new
chrome_bin_path = ENV.fetch('GOOGLE_CHROME_SHIM', nil)
options.binary = chrome_bin_path if chrome_bin_path
options.add_argument('--headless')
driver = Selenium::WebDriver.for :chrome, options: options
but I'm still getting the error in the last line.
Update 2:
I moved to Dokku instead of Heroku and I get the same error. Selenium::WebDriver::Error::WebDriverError: unable to connect to chromedriver 127.0.0.1:9515
.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…