To save a screenshot automatically when any scenario fails, add the following in features/support/env.rb
After do |scenario|
if scenario.failed?
timestamp = "#{Time.zone.now.strftime('%Y-%m-%d-%H:%M:%S')}"
screenshot_name = "screenshot-#{scenario.name.parameterize.underscore}-#{timestamp}.png"
screenshot_path = "#{Rails.root.join('tmp/capybara')}/#{screenshot_name}"
Capybara.page.save_screenshot(screenshot_path)
end
end