Today I Learned

Configuring capybara-screenshot with Heroku

Due to many problems with our capybara-based automations we execute in Sidekiq on Heroku, we did need some visual feedback of what is going wrong. Unfortunately due to read-only nature of Heroku’s file system we did need to customize capybara-screenshot a bit to achieve this functionality.

# initializers/capybara_screenshot.rb

Capybara::Screenshot.s3_configuration = {
  s3_client_credentials: {
    access_key_id: ENV['DEBUG_BUCKET_S3_KEY'],
    secret_access_key: ENV['DEBUG_BUCKET_S3_SECRET'],
  bucket_name: ENV['DEBUG_BUCKET_S3_BUCKET']

# Default available methods use lunchy gem. 
# We do neither need nor want that. 
# Hence introducing simplified version.
Capybara::Screenshot.class_eval do
  def self.save_screenshot
    new_saver(Capybara,, false).save

Capybara.save_path = '/tmp' # Writeable directory on heroku

Then, we have decided to rescue and re-raise all exceptions, but also save a screenshot in the process…

rescue => exception # rubocop:disable Style/RescueStandardError
  raise exception