leifcr-capybara-screenshot 1.0.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +13 -0
  5. data/Appraisals +19 -0
  6. data/CHANGELOG.md +256 -0
  7. data/Gemfile +9 -0
  8. data/LICENSE +19 -0
  9. data/README.md +315 -0
  10. data/Rakefile +40 -0
  11. data/capybara-screenshot.gemspec +39 -0
  12. data/gemfiles/cucumber.1.3.gemfile +11 -0
  13. data/gemfiles/cucumber.2.4.gemfile +11 -0
  14. data/gemfiles/latest.gemfile +10 -0
  15. data/gemfiles/rspec.3.0.gemfile +11 -0
  16. data/gemfiles/spinach.0.8.gemfile +11 -0
  17. data/lib/capybara-screenshot/callbacks.rb +44 -0
  18. data/lib/capybara-screenshot/capybara.rb +26 -0
  19. data/lib/capybara-screenshot/cucumber.rb +28 -0
  20. data/lib/capybara-screenshot/helpers.rb +28 -0
  21. data/lib/capybara-screenshot/minitest.rb +36 -0
  22. data/lib/capybara-screenshot/pruner.rb +48 -0
  23. data/lib/capybara-screenshot/rspec/base_reporter.rb +21 -0
  24. data/lib/capybara-screenshot/rspec/html_embed_reporter.rb +25 -0
  25. data/lib/capybara-screenshot/rspec/html_link_reporter.rb +37 -0
  26. data/lib/capybara-screenshot/rspec/json_reporter.rb +19 -0
  27. data/lib/capybara-screenshot/rspec/text_reporter.rb +39 -0
  28. data/lib/capybara-screenshot/rspec/textmate_link_reporter.rb +19 -0
  29. data/lib/capybara-screenshot/rspec.rb +95 -0
  30. data/lib/capybara-screenshot/s3_saver.rb +64 -0
  31. data/lib/capybara-screenshot/saver.rb +131 -0
  32. data/lib/capybara-screenshot/spinach.rb +26 -0
  33. data/lib/capybara-screenshot/testunit.rb +39 -0
  34. data/lib/capybara-screenshot/version.rb +5 -0
  35. data/lib/capybara-screenshot.rb +217 -0
  36. data/spec/cucumber/cucumber_spec.rb +89 -0
  37. data/spec/cucumber/step_definitions/step_definitions.rb +18 -0
  38. data/spec/cucumber/support/env.rb +17 -0
  39. data/spec/feature/minitest_spec.rb +79 -0
  40. data/spec/feature/testunit_spec.rb +77 -0
  41. data/spec/rspec/rspec_spec.rb +158 -0
  42. data/spec/spec_helper.rb +34 -0
  43. data/spec/spinach/spinach_spec.rb +60 -0
  44. data/spec/spinach/support/spinach_failure.rb +41 -0
  45. data/spec/support/aruba.rb +2 -0
  46. data/spec/support/common_setup.rb +67 -0
  47. data/spec/support/html_reporter_context.rb +28 -0
  48. data/spec/support/test_app.rb +13 -0
  49. data/spec/unit/base_reporter_spec.rb +25 -0
  50. data/spec/unit/capybara-screenshot_rspec_spec.rb +48 -0
  51. data/spec/unit/capybara-screenshot_spec.rb +121 -0
  52. data/spec/unit/capybara_spec.rb +50 -0
  53. data/spec/unit/pruner_spec.rb +108 -0
  54. data/spec/unit/rspec_reporters/html_embed_reporter_spec.rb +18 -0
  55. data/spec/unit/rspec_reporters/html_link_reporter_spec.rb +27 -0
  56. data/spec/unit/rspec_reporters/text_reporter_spec.rb +98 -0
  57. data/spec/unit/rspec_reporters/textmate_link_reporter_spec.rb +39 -0
  58. data/spec/unit/s3_saver_spec.rb +132 -0
  59. data/spec/unit/saver_spec.rb +366 -0
  60. metadata +264 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7514778e4e78652cf17308678a13a90f0cbec61e
4
+ data.tar.gz: a2ff656c191ce42e534486acf6fd4b569c3d0fdf
5
+ SHA512:
6
+ metadata.gz: 67060ef950c691b4db170d6db8c5ac4928043cda03fb2340d5daa8dcbc129e51df2d6ca27ac91c4801a2bf83b4aa7f1dad7f7016bb2fd126be6c191924a05f1c
7
+ data.tar.gz: c62e86fe6ad4e6faa3bd86f55e3735dbb69daef22c6fd62385c9952fd331262b23461ffde6958ce25f00b63b687b6eeae5cfd41bec40be2e8243824e3557ae7f
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ gemfiles/*.lock
5
+ pkg/*
6
+ .rvmrc
7
+ bin
8
+ tmp
9
+ .ruby-version
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ script: "rake travis:ci"
3
+ rvm:
4
+ - 2.0.0
5
+ - 2.1.10
6
+ - 2.2.1
7
+ - 2.3.1
8
+ gemfile:
9
+ - gemfiles/cucumber.1.3.gemfile
10
+ - gemfiles/cucumber.2.4.gemfile
11
+ - gemfiles/latest.gemfile
12
+ - gemfiles/rspec.3.0.gemfile
13
+ - gemfiles/spinach.0.8.gemfile
data/Appraisals ADDED
@@ -0,0 +1,19 @@
1
+ appraise "rspec.3.0" do
2
+ gem "rspec", "3.0"
3
+ end
4
+
5
+ appraise "cucumber.1.3" do
6
+ gem "cucumber", "~>1.3.0"
7
+ end
8
+
9
+ appraise "cucumber.2.4" do
10
+ gem "cucumber", "~>2.4.0"
11
+ end
12
+
13
+ appraise "spinach.0.8" do
14
+ gem "spinach", "~>0.8.0"
15
+ end
16
+
17
+ appraise "latest" do
18
+ # will get latest versions of all gems
19
+ end
data/CHANGELOG.md ADDED
@@ -0,0 +1,256 @@
1
+ 15 Sep 2016 - 1.0.13 -> 1.0.14
2
+
3
+ * CI stable again - dropped CI support for older versions of Ruby and JRuby. It is just too painful and there is no evidence that our users need this or that Capybara Screenshot is indeed broken. It is better to have a reliable build system so that PRs can get merged in reliably and easily.
4
+ * Fixed an inconsistency in the use of `save_and_open_page_path`
5
+ * Improved debugging of Aruba tests so that contributors can easily understand why their builds break
6
+ * Path fixes thanks to [Ryan McGarvey](https://github.com/ryanmcgarvey)
7
+
8
+ 23 May 2016 - 1.0.12 -> 1.0.13
9
+
10
+ * Fixes [mkmf bug 162](https://github.com/mattheworiordan/capybara-screenshot/issues/162) and [mkmf bug 174](https://github.com/mattheworiordan/capybara-screenshot/issues/174)
11
+ * Fix for `Capybara.save_path` method existence assumption
12
+
13
+ 29 March 2016 - 1.0.11 -> 1.0.12
14
+
15
+ * [Aruba upgrade - passing CI](https://github.com/mattheworiordan/capybara-screenshot/pull/156)
16
+ * [imgcat support](https://github.com/mattheworiordan/capybara-screenshot/pull/153)
17
+ * [Fix for capaybara root when Rails not defined](https://github.com/mattheworiordan/capybara-screenshot/pull/139)
18
+ * [Fix using_session_with_screenshot](https://github.com/mattheworiordan/capybara-screenshot/pull/132)
19
+ * [Skip screenshot on skipped test](https://github.com/mattheworiordan/capybara-screenshot/pull/131)
20
+ * [Don't output screenshot paths if not saved](https://github.com/mattheworiordan/capybara-screenshot/pull/128)
21
+
22
+ 22 July 2015 - 1.0.10 -> 1.0.11
23
+
24
+ * [Support for Fuubar reporter](https://github.com/mattheworiordan/capybara-screenshot/pull/137)
25
+
26
+ Thanks to [Kai Schlichting](https://github.com/lacco)
27
+
28
+ 29 June 2015 - 1.0.9 -> 1.0.10
29
+
30
+ * [Small fix to memoization](https://github.com/mattheworiordan/capybara-screenshot/pull/134) plus [mini refactor](https://github.com/mattheworiordan/capybara-screenshot/commit/1db950bc53c729b26b8881d058a8781d6e7611b8)
31
+
32
+ Thanks to [Systho](https://github.com/Systho)
33
+
34
+ 6 April 2015 - 1.0.8 -> 1.0.9
35
+ -----------
36
+
37
+ * [Improved file links within screenshot output](https://github.com/mattheworiordan/capybara-screenshot/pull/123)
38
+
39
+ Thanks to [Jan Lelis](https://github.com/janlelis)
40
+
41
+ 6 April 2015 - 1.0.7 -> 1.0.8
42
+ -----------
43
+
44
+ * Less aggressive pruning
45
+
46
+ 9 March 2015 - 1.0.6 -> 1.0.7
47
+ -----------
48
+
49
+ * Fix capybara-webkit bug, see https://github.com/mattheworiordan/capybara-screenshot/issues/119
50
+ * Fix Travis CI builds in Ruby < 2.1 and added Ruby 2.2 support
51
+
52
+ 8 March 2015 - 1.0.5 -> 1.0.6
53
+ -----------
54
+
55
+ * Removed dependency on the colored gem
56
+
57
+ Thanks to [François Bernier](https://github.com/fbernier)
58
+
59
+ 10 Feburary 2015 - 1.04 -> 1.0.5
60
+ -----------
61
+
62
+ * Added support for appending a random string to the filename
63
+
64
+ Thanks to [Brad Wedell](https://github.com/streetlogics)
65
+
66
+ 5 January 2015 - 1.0.3 -> 1.0.4
67
+ -----------
68
+
69
+ * Added support for Poltergeist Billy
70
+ * Don't initialize a new Capybara::Session in after hook
71
+
72
+ Thanks to [Neodude](https://github.com/neodude) and [Dominik Masur](https://github.com/dmasur)
73
+
74
+ 1 October 2014 - 1.0.2 -> 1.0.3
75
+ -----------
76
+
77
+ * Added ability to prune screenshots automatically, see https://github.com/mattheworiordan/capybara-screenshot/pull/100
78
+
79
+ Thanks to [Anton Kolomiychuk](https://github.com/akolomiychuk) for his contribution.
80
+
81
+ 27 September 2014 - 1.0.1 -> 1.0.2
82
+ -----------
83
+
84
+ * Improved documentation to cover RSpec 3's new approach to using `rails_helper` in place of `spec_helper` for Rails tests
85
+ * Updated documentation to use Ruby formatting in language blocks
86
+ * Removed need to manually `require 'capybara-screenshot'` for RSpec
87
+
88
+ 18 September 2014 - 1.0.0 -> 1.0.1
89
+ -----------
90
+
91
+ * Hot fix for RSpec version issue that assumed RSpec base library was always available, now uses `RSpec::Core::VERSION`
92
+ * Improve Travis CI performance and stability
93
+
94
+ 18 September 2014 - 0.3.22 -> 1.0.0
95
+ -----------
96
+
97
+ Because of the broad test coverage now across RSpec, Cucumber, Spinach, Minitest and TestUnit using [Aruba](https://github.com/cucumber/aruba), I feel that this gem is ready for its first major release. New features and refactoring can now reliably be done without the fear of regressions.
98
+
99
+ The major changes in this 1.0 release are:
100
+
101
+ * Acceptance test coverage for RSpec, Cucumber, Spinach, Minitest and TestUnit
102
+ * Travis CI test coverage across a matrix of old and new versions of the aforementioned testing frameworks, see https://github.com/mattheworiordan/capybara-screenshot/blob/master/.travis.yml
103
+ * Support for RSpec 3 using the custom formatters
104
+ * Support for sessions using `using_session`, see https://github.com/mattheworiordan/capybara-screenshot/pull/91 for more info
105
+ * Support for RSpec DocumentationFormatter
106
+ * Considerable refactoring of the test suite
107
+
108
+ Special thanks goes to [Andrew Brown](https://github.com/dontfidget) who has contributed a huge amount of the code that has helped enable this Gem to have its stable major version release.
109
+
110
+ 22 July 2014 - 0.3.21 -> 0.3.22
111
+ -----------
112
+
113
+ Replaced [colorize](https://rubygems.org/gems/colorize) gem with [colored](https://rubygems.org/gems/colored) due to license issue, see https://github.com/mattheworiordan/capybara-screenshot/issues/93.
114
+
115
+ 22 July 2014 - 0.3.20 -> 0.3.21
116
+ -----------
117
+
118
+ As a result of recent merges and insufficient test coverage, it seems that for test suites other than RSpec the HTML or Image screenshot path was no longer being outputted in the test results. This has now been fixed, and screenshot output format for RSpec and all other test suites has been standardised.
119
+
120
+ 11 July 2014 - 0.3.19 -> 0.3.20
121
+ -----------
122
+
123
+ * Added reporters to improve screenshot info in RSpec output
124
+ * Added support for Webkit options such as width and height
125
+
126
+ Thanks to https://github.com/multiplegeorges and https://github.com/noniq
127
+
128
+ 2 April 2014 - 0.3.18 -> 0.3.19
129
+ -----------
130
+
131
+ * Added support Spinach, thanks to https://github.com/suchitpuri
132
+
133
+ 2 March 2014 - 0.3.16 -> 0.3.17
134
+ -----------
135
+
136
+ * Added support for RSpec 3 and cleaned up the logging so there is less noise within the test results when a driver does not support a particular format.
137
+ * Updated Travis to test against Ruby 2.0 and Ruby 2.1
138
+
139
+ Thanks to https://github.com/noniq
140
+
141
+ 7 January 2014
142
+ -----------
143
+
144
+ Bug fix for Minitest 5, thanks to https://github.com/cschramm
145
+
146
+
147
+ 12 September 2013
148
+ -----------
149
+
150
+ Added support for Test Unit, fixed RSpec deprecation warnings and fixed a dependency issue.
151
+
152
+ Thanks to:
153
+
154
+ * https://github.com/budnik
155
+ * https://github.com/jkraemer
156
+ * https://github.com/mariovisic
157
+
158
+
159
+ 23 July 2013
160
+ -----------
161
+
162
+ https://github.com/stevenwilkin contributed code to display a warning for [Mechanize](http://mechanize.rubyforge.org/) users.
163
+
164
+ 3 June 2013
165
+ -----------
166
+
167
+ Dropped Ruby 1.8 support for this Gem because of conflicts with Nokogiri requiring a later version of Ruby. Instead, there is a new branch https://github.com/mattheworiordan/capybara-screenshot/tree/ruby-1.8-support which can be used if requiring backwards compatabiltiy.
168
+
169
+ 18 Apr 2013
170
+ -----------
171
+
172
+ Improved documentation, Ruby 1.8.7 support by not allowing Capybara 2.1 to be used, improved Sinatra support.
173
+ RSpec screenshot fix to only screenshot when applicable: https://github.com/mattheworiordan/capybara-screenshot/issues/44
174
+
175
+ 07 Jan 2013
176
+ -----------
177
+
178
+ Support for Terminus, thanks to https://github.com/jamesotron
179
+
180
+ 27 Dec 2012
181
+ -----------
182
+
183
+ Previos version bump broke Ruby 1.8.7 support, so Travis CI build added to this Gem and Ruby 1.8.7 support along with JRuby support added.
184
+
185
+ 30 Oct 2012 - Significant version bump 0.3
186
+ -----------
187
+
188
+ After some consideration, and continued problems with load order of capybara-screenshot in relation to other required gems, the commits from @adzap in the pull request https://github.com/mattheworiordan/capybara-screenshot/pull/29 have been incorporated. Moving forwards, for every testing framework you use, you will be required to add an explicit require.
189
+
190
+
191
+ 15 Feb 2012
192
+ -----------
193
+
194
+ Merged pull request https://github.com/mattheworiordan/capybara-screenshot/pull/14 to limit when capybara-screenshot is fired for RSpec
195
+
196
+ 30 Jan 2012
197
+ -----------
198
+
199
+ Merged pull request from https://github.com/hlascelles to support Padrino
200
+
201
+ 15 Jan 2012
202
+ -----------
203
+
204
+ Removed unnecessary and annoying warning that a screen shot cannot be taken. This message was being shown when RSpec tests were run that did not even invoke Capybara
205
+
206
+ 13 Jan 2012
207
+ -----------
208
+
209
+ Updated documentation to reflect support for more frameworks, https://github.com/mattheworiordan/capybara-screenshot/issues/9
210
+
211
+ 3 Jan 2012
212
+ ----------
213
+
214
+ Removed Cucumber dependency https://github.com/mattheworiordan/capybara-screenshot/issues/7
215
+ Allowed PNG save path to be configured using capybara.save_and_open_page_path
216
+
217
+ 3 December 2011
218
+ ---------------
219
+
220
+ More robust handling of Minitest for users who have it installed as a dependency
221
+ https://github.com/mattheworiordan/capybara-screenshot/issues/5
222
+
223
+
224
+ 2 December 2011
225
+ ---------------
226
+
227
+ Fixed bug related to teardown hook not being available in Minitest for some reason (possibly version issues).
228
+ https://github.com/mattheworiordan/capybara-screenshot/issues/5
229
+
230
+ 24 November 2011
231
+ ----------------
232
+
233
+ Added support for:
234
+
235
+ * More platforms (Poltergeist)
236
+ * Removed Rails dependencies (bug)
237
+ * Added screenshot capability for Selenium
238
+ * Added support for embed for HTML reports
239
+
240
+ Thanks to [https://github.com/rb2k](https://github.com/rb2k) for 2 [great commits](https://github.com/mattheworiordan/capybara-screenshot/pull/4)
241
+
242
+ 16 November 2011
243
+ ----------------
244
+
245
+ Added support for Minitest using teardown hooks
246
+
247
+
248
+ 16 November 2011
249
+ ----------------
250
+
251
+ Added support for RSpec by adding a RSpec configuration after hook and checking if Capybara is being used.
252
+
253
+ 15 November 2011
254
+ ----------------
255
+
256
+ Ensured that tests run other than Cucumber won't fail. Prior to this Cucumber was required.
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in capybara-screenshot.gemspec
4
+ gemspec
5
+
6
+ gem 'rack', '~> 1.0'
7
+ gem 'rake', '~> 10.0'
8
+ gem 'appraisal', '~> 2.0'
9
+ gem 'aruba', '~> 0.14.0'
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2011 Matthew O'Riordan, inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,315 @@
1
+ capybara-screenshot gem
2
+ =======================
3
+
4
+ [![Build Status](https://travis-ci.org/mattheworiordan/capybara-screenshot.png)](https://travis-ci.org/mattheworiordan/capybara-screenshot)
5
+ [![Code Climate](https://d3s6mut3hikguw.cloudfront.net/github/mattheworiordan/capybara-screenshot.png)](https://codeclimate.com/github/mattheworiordan/capybara-screenshot)
6
+ [![Gem Version](https://badge.fury.io/rb/capybara-screenshot.svg)](http://badge.fury.io/rb/capybara-screenshot)
7
+
8
+ #### Capture a screen shot for every test failure automatically!
9
+
10
+ `capybara-screenshot` used with [Capybara](https://github.com/jnicklas/capybara) and [Cucumber](http://cukes.info/), [Rspec](https://www.relishapp.com/rspec) or [Minitest](https://github.com/seattlerb/minitest), will capture a screen shot for each failure in your test suite. The HTML for the failed page, and a screenshot image (when using [capybara-webkit](https://github.com/thoughtbot/capybara-webkit), [Selenium](http://seleniumhq.org/) or [poltergeist](https://github.com/jonleighton/poltergeist)) is saved into `$APPLICATION_ROOT/tmp/capybara`.
11
+
12
+ Having screenshots readily available for each test failure is incredibly helpful when trying to quickly diagnose a problem in your failing steps. You can view the source code, and have a screen shot of the page (when applicable), at the time of each failure.
13
+
14
+ _Please note that Ruby 1.9+ is required to use this Gem. For Ruby 1.8 support, please see the [capybara-screenshot Ruby 1.8 branch](https://github.com/mattheworiordan/capybara-screenshot/tree/ruby-1.8-support)_
15
+
16
+ Installation
17
+ -----
18
+
19
+ ### Step 1: install the gem
20
+
21
+ Using Bundler, add the following to your Gemfile
22
+
23
+ ```ruby
24
+ gem 'capybara-screenshot', :group => :test
25
+ ```
26
+
27
+ or install manually using Ruby Gems:
28
+
29
+ ```
30
+ gem install capybara-screenshot
31
+ ```
32
+
33
+ ### Step 2: load capybara-screenshot into your tests
34
+
35
+ #### Cucumber
36
+
37
+ In env.rb or a support file, please add:
38
+
39
+ ```ruby
40
+ require 'capybara-screenshot/cucumber'
41
+ ```
42
+
43
+ #### RSpec
44
+
45
+ In rails_helper.rb, spec_helper.rb, or a support file, after the require for 'capybara/rspec', please add:
46
+
47
+ ```ruby
48
+ # remember: you must require 'capybara/rspec' first
49
+ require 'capybara-screenshot/rspec'
50
+ ```
51
+
52
+ *Note: As of RSpec Rails 3.0, it is recommended that all your Rails environment code is loaded into `rails_helper.rb` instead of `spec_helper.rb`, and as such, the capybara-screenshot require should be located in `rails_helper.rb`. See the [RSpec Rails 3.0 upgrade notes](https://www.relishapp.com/rspec/rspec-rails/v/3-0/docs/upgrade) for more info.*
53
+
54
+ #### Minitest
55
+
56
+ Typically in 'test/test_helper.rb', please add:
57
+
58
+ ```ruby
59
+ require 'capybara-screenshot/minitest'
60
+ ```
61
+
62
+ Also, consider adding `include Capybara::Screenshot::MiniTestPlugin` to any test classes that fail. For example, to capture screenshots for all failing integration tests in minitest-rails, try something like:
63
+
64
+ ```ruby
65
+ class ActionDispatch::IntegrationTest
66
+ include Capybara::Screenshot::MiniTestPlugin
67
+ # ...
68
+ end
69
+ ```
70
+
71
+ #### Test::Unit
72
+
73
+ Typically in 'test/test_helper.rb', please add:
74
+
75
+ ```ruby
76
+ require 'capybara-screenshot/testunit'
77
+ ```
78
+
79
+ By default, screenshots will be captured for `Test::Unit` tests in the path 'test/integration'. You can add additional paths as:
80
+
81
+ ```ruby
82
+ Capybara::Screenshot.testunit_paths << 'test/feature'
83
+ ```
84
+
85
+
86
+ Manual screenshots
87
+ ----
88
+
89
+ If you require more control, you can generate the screenshot on demand rather than on failure. This is useful
90
+ if the failure occurs at a point where the screen shot is not as useful for debugging a rendering problem. This
91
+ can be more useful if you disable the auto-generate on failure feature with the following config
92
+
93
+ ```ruby
94
+ Capybara::Screenshot.autosave_on_failure = false
95
+ ```
96
+
97
+ Anywhere the Capybara DSL methods (visit, click etc.) are available so too are the screenshot methods.
98
+
99
+ ```ruby
100
+ screenshot_and_save_page
101
+ ```
102
+
103
+ Or for screenshot only, which will automatically open the image.
104
+
105
+ ```ruby
106
+ screenshot_and_open_image
107
+ ```
108
+
109
+ These are just calls on the main library methods.
110
+
111
+ ```ruby
112
+ Capybara::Screenshot.screenshot_and_save_page
113
+ Capybara::Screenshot.screenshot_and_open_image
114
+ ```
115
+
116
+ Better looking HTML screenshots
117
+ -------------------------------
118
+
119
+ By the default, HTML screenshots will not look very good when opened in a browser. This happens because the browser can't correctly resolve relative paths like `<link href="/assets/...." />`, which stops CSS, images, etc... from beind loaded. To get a nicer looking page, configure Capybara with:
120
+
121
+ ```ruby
122
+ Capybara.asset_host = 'http://localhost:3000'
123
+ ```
124
+
125
+ This will cause Capybara to add `<base>http://localhost:3000</base>` to the HTML file, which gives the browser enough information to resolve relative paths. Next, start a rails server in development mode, on port 3000, to respond to requests for assets:
126
+
127
+ ```bash
128
+ rails s -p 3000
129
+ ```
130
+
131
+ Now when you open the page, you should have something that looks much better. You can leave this setup in place and use the default HTML pages when you don't care about the presentation, or start the rails server when you need something better looking.
132
+
133
+ Driver configuration
134
+ --------------------
135
+
136
+ The gem supports the default rendering method for Capybara to generate the screenshot, which is:
137
+
138
+ ```ruby
139
+ page.driver.render(path)
140
+ ```
141
+
142
+ There are also some specific driver configurations for Selenium, Webkit, and Poltergeist. See [the definitions here](https://github.com/mattheworiordan/capybara-screenshot/blob/master/lib/capybara-screenshot.rb). The Rack::Test driver, Rails' default, does not allow
143
+ rendering, so it has a driver definition as a noop.
144
+
145
+ Capybara-webkit defaults to a screenshot size of 1000px by 10px. To specify a custom size, use the following option:
146
+
147
+ ```ruby
148
+ Capybara::Screenshot.webkit_options = { width: 1024, height: 768 }
149
+ ```
150
+
151
+ If a driver is not found the default rendering will be used. If this doesn't work with your driver, then you can
152
+ add another driver configuration like so
153
+
154
+ ```ruby
155
+ # The driver name should match the Capybara driver config name.
156
+ Capybara::Screenshot.register_driver(:exotic_browser_driver) do |driver, path|
157
+ driver.super_dooper_render(path)
158
+ end
159
+ ```
160
+
161
+ If your driver is based on existing browser driver, like Firefox, instead of `.super_dooper_render` do `driver.browser.save_screenshot path`.
162
+
163
+
164
+ Custom screenshot filename
165
+ --------------------------
166
+
167
+ If you want to control the screenshot filename for a specific test library, to inject the test name into it for example,
168
+ you can override how the basename is generated for the file like so
169
+
170
+ ```ruby
171
+ Capybara::Screenshot.register_filename_prefix_formatter(:rspec) do |example|
172
+ "screenshot_#{example.description.gsub(' ', '-').gsub(/^.*\/spec\//,'')}"
173
+ end
174
+ ```
175
+
176
+ By default capybara-screenshot will append a timestamp to the basename. If you want to disable this behavior set the following option:
177
+
178
+ ```ruby
179
+ Capybara::Screenshot.append_timestamp = false
180
+ ```
181
+
182
+
183
+ Custom screenshot directory
184
+ --------------------------
185
+ By default, when running under Rails, Sinatra, and Padrino, screenshots are saved into `$APPLICATION_ROOT/tmp/capybara`. Otherwise, they're saved under `Dir.pwd`.
186
+ If you want to customize the location, override the file path as:
187
+
188
+ ```ruby
189
+ Capybara.save_path = "/file/path"
190
+ ```
191
+
192
+
193
+ Uploading screenshots to S3
194
+ --------------------------
195
+ You can configure capybara-screenshot to automatically save your screenshots to an AWS S3 bucket.
196
+
197
+ First, install the `aws-sdk` gem or add it to your Gemfile
198
+
199
+ ```ruby
200
+ gem 'capybara-screenshot', :group => :test
201
+ gem 'aws-sdk', :group => :test
202
+ ```
203
+
204
+ Next, configure capybara-screenshot with your S3 credentials, the bucket to save to, and an optional region (default: `us-east-1`).
205
+
206
+ ```ruby
207
+ Capybara::Screenshot.s3_configuration = {
208
+ s3_client_credentials: {
209
+ access_key_id: "my_access_key_id",
210
+ secret_access_key: "my_secret_access_key",
211
+ region: "eu-central-1"
212
+ },
213
+ bucket_name: "my_screenshots"
214
+ }
215
+ ```
216
+
217
+
218
+ Pruning old screenshots automatically
219
+ --------------------------
220
+ By default screenshots are saved indefinitely, if you want them to be automatically pruned on a new failure, then you can specify one of the following prune strategies as follows:
221
+
222
+ ```ruby
223
+ # Keep only the screenshots generated from the last failing test suite
224
+ Capybara::Screenshot.prune_strategy = :keep_last_run
225
+
226
+ # Keep up to the number of screenshots specified in the hash
227
+ Capybara::Screenshot.prune_strategy = { keep: 20 }
228
+ ```
229
+
230
+ Callbacks
231
+ ---------
232
+
233
+ You can hook your own logic into callbacks after the html/screenshot has been saved.
234
+
235
+ ```ruby
236
+ # after Saver#save_html
237
+ Capybara::Screenshot.after_save_html do |path|
238
+ mail = Mail.new do
239
+ delivery_method :sendmail
240
+ from 'capybara-screenshot@example.com'
241
+ to 'dev@example.com'
242
+ subject 'Capybara Screenshot'
243
+ add_file File.read path
244
+ end
245
+ mail.delivery_method :sendmail
246
+ mail.deliver
247
+ end
248
+
249
+ # after Saver#save_screenshot
250
+ Capybara::Screenshot.after_save_screenshot do |path|
251
+ # ...
252
+ end
253
+ ```
254
+
255
+ Information about screenshots in RSpec output
256
+ ---------------------------------------------
257
+
258
+ By default, capybara-screenshot extend RSpec’s formatters to include a link to the screenshot and/or saved html page for each failed spec. If you want to disable this feature completely (eg. to avoid problems with CI tools), use:
259
+
260
+ ```ruby
261
+ Capybara::Screenshot::RSpec.add_link_to_screenshot_for_failed_examples = false
262
+ ```
263
+
264
+ It’s also possible to directly embed the screenshot image in the output if you’re using RSpec’s HtmlFormatter:
265
+
266
+ ```ruby
267
+ Capybara::Screenshot::RSpec::REPORTERS["RSpec::Core::Formatters::HtmlFormatter"] = Capybara::Screenshot::RSpec::HtmlEmbedReporter
268
+ ```
269
+
270
+ If you want to further customize the information added to RSpec’s output, just implement your own reporter class and customize `Capybara::Screenshot::RSpec::REPORTERS` accordingly. See [rspec.rb](lib/capybara-screenshot/rspec.rb) for more info.
271
+
272
+
273
+ Common problems
274
+ ---------------
275
+
276
+ If you have recently upgraded from v0.2, or you find that screen shots are not automatically being generated, then it's most likely you have not included the necessary `require` statement for your testing framework described above. As of version 0.3, without the explicit require, Capybara-Screenshot will not automatically take screen shots. Please re-read the installation instructions above.
277
+
278
+ Also make sure that you're not calling `Capybara.reset_sessions!` before the screenshot hook runs. For RSpec you want to make sure that you're using `append_after` instead of `after`, for instance:
279
+
280
+ ```ruby
281
+ config.append_after(:each) do
282
+ Capybara.reset_sessions!
283
+ end
284
+ ```
285
+
286
+ [Raise an issue on the Capybara-Screenshot issue tracker](https://github.com/mattheworiordan/capybara-screenshot/issues) if you are still having problems.
287
+
288
+ Repository & Contributing to this Gem
289
+ -------------------------------------
290
+
291
+ #### Bugs
292
+
293
+ Please raise an issue at [https://github.com/mattheworiordan/capybara-screenshot/issues](https://github.com/mattheworiordan/capybara-screenshot/issues) and ensure you provide sufficient detail to replicate the problem.
294
+
295
+ #### Contributions
296
+
297
+ Contributions are welcome. Please fork this gem, and submit a pull request. New features must include test coverage and must pass on all versions of the testing frameworks supported. Run `appraisal` to set up the your Gems. then `appraisal "rake travis:ci"` locally to test your changes against all versions of testing framework gems supported.
298
+
299
+ #### Rubygems
300
+
301
+ The gem details on RubyGems.org can be found at [https://rubygems.org/gems/capybara-screenshot](https://rubygems.org/gems/capybara-screenshot)
302
+
303
+ About
304
+ -----
305
+
306
+ This gem was written by **Matthew O'Riordan**, with contributions from [many kind people](https://github.com/mattheworiordan/capybara-screenshot/network/members).
307
+
308
+ - [http://mattheworiordan.com](http://mattheworiordan.com)
309
+ - [@mattheworiordan](http://twitter.com/#!/mattheworiordan)
310
+ - [Linked In](http://www.linkedin.com/in/lemon)
311
+
312
+ License
313
+ -------
314
+
315
+ Copyright © 2016 Matthew O'Riordan, inc. It is free software, and may be redistributed under the terms specified in the LICENSE file.