From 394019b70c5a08f52a626f5185251f2a27f50a76 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Mon, 2 Jul 2018 12:37:41 +0200 Subject: [PATCH] specs: save a screenshot of failing integration tests --- Gemfile | 8 ++++++-- Gemfile.lock | 4 ++++ spec/spec_helper.rb | 10 ++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 35094dfd9..2b492bc4e 100644 --- a/Gemfile +++ b/Gemfile @@ -124,19 +124,23 @@ gem "administrate" gem 'rack-mini-profiler' group :test do - gem 'capybara' gem 'launchy' gem 'factory_bot' gem 'database_cleaner' gem 'webmock' gem 'shoulda-matchers', require: false - gem 'capybara-selenium' gem 'timecop' gem 'guard' gem 'guard-rspec', require: false gem 'guard-livereload', require: false gem 'vcr' gem 'rails-controller-testing' + + # Integration testing + gem 'capybara' + gem 'capybara-selenium' + # Save a dump of the page when an integration test fails + gem 'capybara-screenshot' end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 43089c584..e2eae1d09 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -118,6 +118,9 @@ GEM rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (>= 2.0, < 4.0) + capybara-screenshot (1.0.21) + capybara (>= 1.0, < 4) + launchy capybara-selenium (0.0.6) capybara selenium-webdriver @@ -798,6 +801,7 @@ DEPENDENCIES browser byebug capybara + capybara-screenshot capybara-selenium carrierwave carrierwave-i18n diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e693207dd..9f51925f3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -22,6 +22,7 @@ ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../config/environment', __dir__) require 'rspec/rails' require 'capybara/rspec' +require 'capybara-screenshot/rspec' require 'database_cleaner' require 'webmock/rspec' require 'shoulda-matchers' @@ -50,6 +51,15 @@ ActiveSupport::Deprecation.silenced = true Capybara.default_max_wait_time = 1 +# Save a snapshot of the HTML page when an integration test fails +Capybara::Screenshot.autosave_on_failure = true +# Keep only the screenshots generated from the last failing test suite +Capybara::Screenshot.prune_strategy = :keep_last_run +# Tell Capybara::Screenshot how to take screenshots when using the headless_chrome driver +Capybara::Screenshot.register_driver :headless_chrome do |driver, path| + driver.browser.save_screenshot(path) +end + # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f }