This is done locally (without driver_path ), but not on Heroku.
The code:
Selenium::WebDriver::Chrome.driver_path = ENV['GOOGLE_CHROME_SHIM'] browser = Watir::Browser.new :chrome
I confirmed below values ββin geku rails console
ENV['GOOGLE_CHROME_BIN'] => "/app/.apt/opt/google/chrome/chrome" ENV['GOOGLE_CHROME_SHIM'] => "/app/.apt/usr/bin/google-chrome-stable"
Installed builds:
https://github.com/heroku/heroku-buildpack-chromedriver https://github.com/heroku/heroku-buildpack-google-chrome
Current error:
Selenium :: WebDriver :: Error :: WebDriverError: unable to connect to chromedriver 127.0.0.1:9515
A search for unable to connect to chromedriver 127.0.0.1:9515 on SO returns a bunch of results, but no one mentions the hero.
Also:
I considered phantoms. Someone else has earned here, Using a mute browser with Heroku Rails Unicorn package
But it is out of date. Below errors when starting locally.
Selenium support for PhantomJS is deprecated. Use headless Chrome / Firefox or HTMLUnit.
Also tried:
For transparency, I also tried the following.
Change browser = Watir::Browser.new :chrome
In browser = Watir::Browser.new :chrome, headless: true
Although I did not expect this to work.
Also tried:
Removal: https://github.com/heroku/heroku-buildpack-chromedriver
Addendum: https://github.com/heroku/heroku-buildpack-xvfb-google-chrome .
Adding a headless gem.
And by running below the script indicated on the watir gem page, http://watir.com/guides/headless/ .
require 'watir' require 'headless' headless = Headless.new headless.start b = Watir::Browser.start 'www.google.com' puts b.title b.close headless.destroy
Mistake:
Selenium :: WebDriver :: Error :: UnknownError: Unknown error: Cannot find Chrome binary
I assume this failed because I did not specify the location of the chrome binary / gasket. Could not find how to indicate this when using headless in documents.
Tried on a suggestion:
heroku run /usr/bin/chromedriver --app app-name
Run / usr / bin / chromedriver on β¬’ app-name ... up, run.2151
(Hobby) bash: / usr / bin / chromedriver: No such file or directory
Also see below the logs that mention chrome when deployed to heroku:
remote: -----> chromedriver app detected remote: -----> Looking up latest chromedriver version... remote: -----> Downloading chromedriver v2.33... remote: Archive: /tmp/chromedriver.zip remote: inflating: /tmp/build_cd35072c5b766edaa2b565cbff57e5d6/.chromedriver/bin/chromedriver remote: -----> Creating chromedriver export scripts... remote: -----> Google Chrome app detected ... remote: -----> Fetching https:
Progress:
If I ssh to heroku server,
heroku run bash --app app-name
Look for files called chrome ,
find /app/ -name "*chrome*"
/app/.profile.d/chromedriver.sh /app/.profile.d/010_google-chrome.sh /app/.apt/etc/cron.daily/google-chrome /app/.apt/opt/google/chrome /app/.apt/opt/google/chrome/chrome /app/.apt/opt/google/chrome/chrome_100_percent.pak /app/.apt/opt/google/chrome/chrome-sandbox /app/.apt/opt/google/chrome/chrome_200_percent.pak /app/.apt/opt/google/chrome/google-chrome /app/.apt/opt/google/chrome/cron/google-chrome /app/.apt/usr/bin/google-chrome-stable /app/.apt/usr/bin/google-chrome /app/.apt/usr/share/menu/google-chrome.menu /app/.apt/usr/share/doc/google-chrome-stable /app/.apt/usr/share/applications/google-chrome.desktop /app/.apt/usr/share/gnome-control-center/default-apps/google-chrome.xml /app/.apt/usr/share/man/man1/google-chrome.1 /app/.apt/usr/share/appdata/google-chrome.appdata.xml /app/vendor/bundle/ruby/2.4.0/gems/selenium-webdriver-3.7.0/lib/selenium/webdriver/chrome /app/vendor/bundle/ruby/2.4.0/gems/selenium-webdriver-3.7.0/lib/selenium/webdriver/chrome.rb /app/vendor/bundle/ruby/2.4.0/gems/browser-2.4.0/test/unit/chrome_test.rb /app/vendor/bundle/ruby/2.4.0/gems/browser-2.4.0/lib/browser/platform/chrome_os.rb /app/vendor/bundle/ruby/2.4.0/gems/browser-2.4.0/lib/browser/chrome.rb /app/.chromedriver /app/.chromedriver/bin/chromedriver
I see a binary file with chrome edges in /app/.chromedriver/bin/chromedriver .
So i tried
heroku run /app/.chromedriver/bin/chromedriver --app app-name
Result:
Running /app/.chromedriver/bin/chromedriver on β¬’ app-name... up, run.2067 (Hobby) Starting ChromeDriver 2.33.506092 (733a02544d189eeb751fe0d7ddca79a0ee28cce4) on port 9515 Only local connections are allowed.
But then running heroku run rake selenium_namespace:task_one --app app-name gives the same result.
Selenium :: WebDriver :: Error :: WebDriverError: cannot connect to chromedriver 127.0.0.1:9515 ... / app / vendor / ruby ββ-2.4.1 / lib / ruby ββ/ 2.4.0 / net / http.rb: 906: in `rescue in block in connect ': Failed to open TCP connection from 127.0.0.1:9515 (Connection refused - connection (2) for port" 127.0.0.1 "9515) (Errno :: ECONNREFUSED) ...