From 284170040d1a0051eac9bd930b304573b293b3af Mon Sep 17 00:00:00 2001 From: Vinh Nguyen Date: Thu, 8 Oct 2015 16:13:40 +0700 Subject: [PATCH] Add Capybara-screenshot --- Gemfile | 1 + Gemfile.lock | 6 +++- README.md | 3 ++ spec/support/capybara_screenshot.rb | 46 +++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 spec/support/capybara_screenshot.rb diff --git a/Gemfile b/Gemfile index 1425ce5..4587f8b 100644 --- a/Gemfile +++ b/Gemfile @@ -37,4 +37,5 @@ group :test do gem 'shoulda-matchers', '3.0.0.rc1' gem 'vcr' gem 'webmock' + gem 'capybara-screenshot' end diff --git a/Gemfile.lock b/Gemfile.lock index 19cd61c..2d73259 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -50,6 +50,9 @@ GEM rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (~> 2.0) + capybara-screenshot (1.0.11) + capybara (>= 1.0, < 3) + launchy childprocess (0.5.6) ffi (~> 1.0, >= 1.0.11) cliver (0.3.2) @@ -260,6 +263,7 @@ PLATFORMS DEPENDENCIES byebug capybara + capybara-screenshot coffee-rails (~> 4.1.0) database_cleaner devise @@ -289,4 +293,4 @@ DEPENDENCIES webmock BUNDLED WITH - 1.10.5 + 1.10.6 diff --git a/README.md b/README.md index 12b6383..e20e1a2 100644 --- a/README.md +++ b/README.md @@ -141,8 +141,11 @@ VCR configuration how-to and examples: [Capybara](https://github.com/jnicklas/capybara) helps you write feature specs that interact with your app's UI as a user does with a browser. +[Capybara Screenshot](https://github.com/mattheworiordan/capybara-screenshot) will automatically save screen shots when a Capybara scenario fails. + Capybara configuration how-to and examples: - [spec/support/capybara.rb](spec/support/capybara.rb) +- [spec/support/capybara_screenshot.rb](spec/support/capybara_screenshot.rb) - [spec/features/home_page_spec.rb](spec/features/home_page_spec.rb) - [spec/features/subscribe_to_newsletter_spec.rb](spec/features/subscribe_to_newsletter_spec.rb) - [spec/features/user_login_and_logout_spec.rb](spec/features/user_login_and_logout_spec.rb) diff --git a/spec/support/capybara_screenshot.rb b/spec/support/capybara_screenshot.rb new file mode 100644 index 0000000..cbbec89 --- /dev/null +++ b/spec/support/capybara_screenshot.rb @@ -0,0 +1,46 @@ +# Installing capybara-screenshot: + +# 0. Check spec/support dir is auto-required in spec/rails_helper.rb. +# +# 1. Add capybara-screenshot to Gemfile: +# +# group :test do +# gem 'capybara-screenshot' +# end +# +# 2. Create a file like this one you're reading in spec/support/capybara-screenshot.rb: + +require 'capybara-screenshot/rspec' + +# Manual screenshot. +# This is useful if the failure occurs at a point where the +# screen shot is not as useful for debugging a rendering problem. + +# Anywhere the Capybara DSL methods (visit, click etc.) are available so +# too are the screenshot methods. Defaults is true +# Capybara::Screenshot.autosave_on_failure = false + +# Specify a custom screenshot size. Default is 1000px +# Capybara::Screenshot.webkit_options = { width: 1024, height: 768 } + +# Custom screenshot file name for a specific test library. +# Capybara::Screenshot.register_filename_prefix_formatter(:rspec) do |example| +# "screenshot_#{example.description.gsub(' ', '-').gsub(/^.*\/spec\//,'')}" +# end + +# Disable time stamp in the basename. Defaults is true +# Capybara::Screenshot.append_timestamp = false + +# Custom screenshot directory. Defaults is `$APPLICATION_ROOT/tmp/capybara` +# Capybara.save_and_open_page_path = "/your/file/path" + +# Pruning old screenshot automatically. Defaults screenshots are saved indefinitely +# +# Keep only the screenshots generated from the last failing test suite +# Capybara::Screenshot.prune_strategy = :keep_last_run +# +# Keep up to the number of screenshots specified in the hash +# Capybara::Screenshot.prune_strategy = { keep: 10 } + +# Disable the screenshots information for each failed spec. Defautls is enable +# Capybara::Screenshot::RSpec.add_link_to_screenshot_for_failed_examples = false