↖️ Show all posts

Ruby, Watir and Chrome on Heroku

Newest Watir / Selenium Combo had a deprecation warning for PhantomJS. I didn’t want to get caught, so it was about time to tackle this.

Heroku is a relatively closed and proprietary PaaS, yet my favourite one. In the past, I added a compiled PhantomJS executable in a bin directory (read more).

Buildpacks for your heroku project

go to your heroku dashboard, select the project and add these buildpacks:

but running Watir still fails:

# runs on local machine just fine
browser = Watir::Browser.new :chrome

heroku bash to the rescue

# in your terminal
$ cd /your/project/path

$ heroku run bash

# on heroku bash
# save the returned paths for future use
$ which google-chrome

$ which chromedriver

Setup Selenium (on production)

Selenium Chrome Documentation

remember to wrap the Watir code in an if clause, so only your heroku project uses the new Selenium settings. I like to set a custom ENV variable on heroku for such things.

Selenium::WebDriver::Chrome.path = "path/to/google-chrome"
Selenium::WebDriver::Chrome.driver_path = "path/to/chromedriver"
browser = Watir::Browser.new :chrome

You now have Watir / Selenium running a headless Chrome browser on heroku.


⬅️ Read previous Read next ➡️