capybara-screenshot 1.0.22 → 1.0.26

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b82c5c74da4902799ac9a61f9eb37449a928254e
4
- data.tar.gz: 8052ba2b86c41f32539463afeddfe07cb275eb0a
2
+ SHA256:
3
+ metadata.gz: b73d3b8338a3c2f426d7835f4396565c0bfe28b939f610337c331099f93f52b5
4
+ data.tar.gz: c5ec9f343c703e5ac2700b84dcde63a094c3609787ea7b1cfbbd1f470a5b0ce4
5
5
  SHA512:
6
- metadata.gz: 7a4fc4c95398c92bec5387f27521623c2ca6c5d7b6dbf07bfa614e63012ccc31625488baf52b6471bdf6d27e8c5254a0af149e7cb3fc220c4b64ce4239fbdbcf
7
- data.tar.gz: 74fc5fb1271e9d7faaf23271719085ea6302a3b74124d764b1d4f5c6b55109329dfc368e1588466cf99d077a071d4cf77ebe40a8b3f68b140522f2442333f655
6
+ metadata.gz: 4cd11454a82290ef985a5341e0dad1eaea6296ca5b6ea1f17522a5f8f43b6c68dd71cfd17426c8204fd352488b6ea876d2e8493b2ec0ce2e575590e13302b456
7
+ data.tar.gz: d17d96491ebc960f4fa47eec58b9dd60610c4a7839e878d8d40c3003cb054e891fc38e958ba42dbcf7ded095385fbb725cdd9e33e368fec51cd89358653c3576
data/.travis.yml CHANGED
@@ -4,9 +4,10 @@ rvm:
4
4
  - 2.0.0
5
5
  - 2.1.10
6
6
  - 2.2.10
7
- - 2.3.7
8
- - 2.4.4
9
- - 2.5.1
7
+ - 2.3.8
8
+ - 2.4.9
9
+ - 2.5.7
10
+ - 2.6.5
10
11
  gemfile:
11
12
  - gemfiles/cucumber.1.3.gemfile
12
13
  - gemfiles/cucumber.2.4.gemfile
data/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ 21 Dec 2021 - 1.0.25 -> 1.0.26
2
+
3
+ * [Take screenshots of current window (when using multiple windows)](https://github.com/mattheworiordan/capybara-screenshot/pull/287)
4
+ * [Fix embedding screenshots into cucumber HTML reports](https://github.com/mattheworiordan/capybara-screenshot/pull/288)
5
+
6
+ 4 Oct 2020 - 1.0.24 -> 1.0.25
7
+
8
+ * [Fix Cucumber 5 deprecation warnings](https://github.com/mattheworiordan/capybara-screenshot/pull/274)
9
+ * [Add support for Cuprite driver](https://github.com/mattheworiordan/capybara-screenshot/pull/270)
10
+ * [Rails system spec compatibility](https://github.com/mattheworiordan/capybara-screenshot/pull/264)
11
+
12
+ 24 Nov 2019 - 1.0.23 -> 1.0.24
13
+
14
+ * [Support Apparition driver](https://github.com/mattheworiordan/capybara-screenshot/commit/273317b241d1d1d8600b32fad998742894424f3b)
15
+
16
+ 10 Jun 2019 - 1.0.22 -> 1.0.23
17
+
18
+ * [Support for Capybara sessions implicitly](https://github.com/mattheworiordan/capybara-screenshot/pull/255). Thanks https://github.com/TylerRick
19
+ * [Support for S3 bucket host configuration](https://github.com/mattheworiordan/capybara-screenshot/pull/252). Thanks https://github.com/machty
20
+
1
21
  21 Oct 2018 - 1.0.21 -> 1.0.22
2
22
 
3
23
  * [Support for S3 URL in HTML screenshots](https://github.com/mattheworiordan/capybara-screenshot/pull/239)
data/Gemfile CHANGED
@@ -4,6 +4,6 @@ source "http://rubygems.org"
4
4
  gemspec
5
5
 
6
6
  gem 'rack', '~> 1.0'
7
- gem 'rake', '~> 10.0'
7
+ gem 'rake', '~> 13.0'
8
8
  gem 'appraisal', '~> 2.0'
9
9
  gem 'aruba', '~> 0.14.0'
data/README.md CHANGED
@@ -5,26 +5,27 @@ capybara-screenshot gem
5
5
  [![Code Climate](https://d3s6mut3hikguw.cloudfront.net/github/mattheworiordan/capybara-screenshot.svg)](https://codeclimate.com/github/mattheworiordan/capybara-screenshot)
6
6
  [![Gem Version](https://badge.fury.io/rb/capybara-screenshot.svg)](http://badge.fury.io/rb/capybara-screenshot)
7
7
 
8
- #### Capture a screen shot for every test failure automatically!
8
+ #### Capture a screenshot for every test failure automatically!
9
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`.
10
+ `capybara-screenshot` used with [Capybara](https://github.com/jnicklas/capybara) alongside [Cucumber](http://cukes.info/), [Rspec](https://www.relishapp.com/rspec) or [Minitest](https://github.com/seattlerb/minitest), will capture a screenshot for each failure in your test suite. Associated screenshot and HTML file
11
+ of the failed page (when using [capybara-webkit](https://github.com/thoughtbot/capybara-webkit), [Selenium](http://seleniumhq.org/), [poltergeist](https://github.com/jonleighton/poltergeist) or [cuprite](https://github.com/machinio/cuprite)) is saved into `$APPLICATION_ROOT/tmp/capybara`.
11
12
 
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
+ Available screenshots for each test failure is incredibly helpful for diagnosing problems quickly in your failing steps. You have the ability to view screenshots (when applicable) and source code at the time of each failure.
13
14
 
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
+ _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
 
16
17
  Installation
17
18
  -----
18
19
 
19
20
  ### Step 1: install the gem
20
21
 
21
- Using Bundler, add the following to your Gemfile
22
+ Using Bundler, add the following to your Gemfile:
22
23
 
23
24
  ```ruby
24
25
  gem 'capybara-screenshot', :group => :test
25
26
  ```
26
27
 
27
- or install manually using Ruby Gems:
28
+ Alternatively, manually install using Ruby Gems:
28
29
 
29
30
  ```
30
31
  gem install capybara-screenshot
@@ -76,7 +77,7 @@ Typically in 'test/test_helper.rb', please add:
76
77
  require 'capybara-screenshot/testunit'
77
78
  ```
78
79
 
79
- By default, screenshots will be captured for `Test::Unit` tests in the path 'test/integration'. You can add additional paths as:
80
+ By default, screenshots will be captured for `Test::Unit` tests in the path 'test/integration'. You can add additional paths:
80
81
 
81
82
  ```ruby
82
83
  Capybara::Screenshot.testunit_paths << 'test/feature'
@@ -86,27 +87,28 @@ Capybara::Screenshot.testunit_paths << 'test/feature'
86
87
  Manual screenshots
87
88
  ----
88
89
 
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
90
+ If you require more control, screenshots can be generated on demand rather than on failure. This is useful
91
+ when screenshots produced at the time of failure are not as useful for debugging a rendering problem.
92
+ Differentiating between manual and failure screenshots can be improved by disabling the auto-generate on
93
+ failure feature:
92
94
 
93
95
  ```ruby
94
96
  Capybara::Screenshot.autosave_on_failure = false
95
97
  ```
96
98
 
97
- Anywhere the Capybara DSL methods (visit, click etc.) are available so too are the screenshot methods.
99
+ Anywhere the Capybara DSL methods (visit, click etc.) are available so too are the screenshot methods:
98
100
 
99
101
  ```ruby
100
102
  screenshot_and_save_page
101
103
  ```
102
104
 
103
- Or for screenshot only, which will automatically open the image.
105
+ Or for screenshot only, which will automatically open the image:
104
106
 
105
107
  ```ruby
106
108
  screenshot_and_open_image
107
109
  ```
108
110
 
109
- These are just calls on the main library methods.
111
+ These are just calls on the main library methods:
110
112
 
111
113
  ```ruby
112
114
  Capybara::Screenshot.screenshot_and_save_page
@@ -116,7 +118,7 @@ Capybara::Screenshot.screenshot_and_open_image
116
118
  Better looking HTML screenshots
117
119
  -------------------------------
118
120
 
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:
121
+ 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 being loaded. To get a nicer looking page, configure Capybara with:
120
122
 
121
123
  ```ruby
122
124
  Capybara.asset_host = 'http://localhost:3000'
@@ -128,7 +130,7 @@ This will cause Capybara to add `<base>http://localhost:3000</base>` to the HTML
128
130
  rails s -p 3000
129
131
  ```
130
132
 
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.
133
+ 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
134
 
133
135
  Driver configuration
134
136
  --------------------
@@ -165,7 +167,7 @@ Custom screenshot filename
165
167
  --------------------------
166
168
 
167
169
  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
170
+ you can override how the basename is generated for the file:
169
171
 
170
172
  ```ruby
171
173
  Capybara::Screenshot.register_filename_prefix_formatter(:rspec) do |example|
@@ -173,7 +175,7 @@ Capybara::Screenshot.register_filename_prefix_formatter(:rspec) do |example|
173
175
  end
174
176
  ```
175
177
 
176
- By default capybara-screenshot will append a timestamp to the basename. If you want to disable this behavior set the following option:
178
+ By default capybara-screenshot will append a timestamp to the basename. If you want to disable this behavior, set the following option:
177
179
 
178
180
  ```ruby
179
181
  Capybara::Screenshot.append_timestamp = false
@@ -183,36 +185,25 @@ Capybara::Screenshot.append_timestamp = false
183
185
  Custom screenshot directory
184
186
  --------------------------
185
187
  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:
188
+ If you want to customize the location, override the file path:
187
189
 
188
190
  ```ruby
189
191
  Capybara.save_path = "/file/path"
190
192
  ```
191
193
 
192
- Usage with multiple Capybara sessions
193
- -------------------------------------
194
-
195
- To make screenshots work with multiple Capybara sessions, replace `Capybara.using_session` with `Capybara.using_session_with_screenshot`:
196
-
197
- ```ruby
198
- Cabybara.using_session_with_screenshot('User 1') do
199
- # screenshots will work and use the correct session
200
- end
201
- ```
202
-
203
194
 
204
195
  Uploading screenshots to S3
205
196
  --------------------------
206
197
  You can configure capybara-screenshot to automatically save your screenshots to an AWS S3 bucket.
207
198
 
208
- First, install the `aws-sdk-s3` gem or add it to your Gemfile
199
+ First, install the `aws-sdk-s3` gem or add it to your Gemfile:
209
200
 
210
201
  ```ruby
211
202
  gem 'aws-sdk-s3', group: :test
212
203
  gem 'capybara-screenshot', group: :test
213
204
  ```
214
205
 
215
- Next, configure capybara-screenshot with your S3 credentials, the bucket to save to, and an optional region (default: `us-east-1`).
206
+ Next, configure capybara-screenshot with your S3 credentials, the bucket to save to, and an optional region (default: `us-east-1`):
216
207
 
217
208
  ```ruby
218
209
  Capybara::Screenshot.s3_configuration = {
@@ -221,10 +212,16 @@ Capybara::Screenshot.s3_configuration = {
221
212
  secret_access_key: "my_secret_access_key",
222
213
  region: "eu-central-1"
223
214
  },
224
- bucket_name: "my_screenshots"
215
+ bucket_name: "my_screenshots",
216
+ # Optionally: Specify the host used to access the uploaded screenshots
217
+ bucket_host: "my_screenshots.s3-eu-central-1.amazonaws.com",
225
218
  }
226
219
  ```
227
220
 
221
+ The access key used for S3 uploads need to have at least the `s3:PutObject` permission.
222
+
223
+ **Note**: If you do not provide the `bucket_host` configuration option, additionally the `s3:GetBucketLocation` permission is required on the bucket for uploads to succeed.
224
+
228
225
  It is also possible to specify the object parameters such as acl.
229
226
  Configure the capybara-screenshot with these options in this way:
230
227
 
@@ -245,7 +242,7 @@ Capybara::Screenshot.s3_configuration = {
245
242
 
246
243
  Pruning old screenshots automatically
247
244
  --------------------------
248
- 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:
245
+ 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:
249
246
 
250
247
  ```ruby
251
248
  # Keep only the screenshots generated from the last failing test suite
@@ -258,7 +255,7 @@ Capybara::Screenshot.prune_strategy = { keep: 20 }
258
255
  Callbacks
259
256
  ---------
260
257
 
261
- You can hook your own logic into callbacks after the html/screenshot has been saved.
258
+ You can hook your own logic into callbacks after the html/screenshot has been saved:
262
259
 
263
260
  ```ruby
264
261
  # after Saver#save_html
@@ -322,7 +319,7 @@ Please raise an issue at [https://github.com/mattheworiordan/capybara-screenshot
322
319
 
323
320
  #### Contributions
324
321
 
325
- 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.
322
+ Contributions are welcome. Please fork this gem and then 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.
326
323
 
327
324
  #### Rubygems
328
325
 
@@ -333,11 +330,12 @@ About
333
330
 
334
331
  This gem was written by **Matthew O'Riordan**, with contributions from [many kind people](https://github.com/mattheworiordan/capybara-screenshot/network/members).
335
332
 
336
- - [http://mattheworiordan.com](http://mattheworiordan.com)
333
+ - [http://mattheworiordan.com](http://mattheworiordan.com), [Technical co-founder & CEO of Ably Realtime](https://ably.com/)
337
334
  - [@mattheworiordan](http://twitter.com/#!/mattheworiordan)
338
- - [Linked In](http://www.linkedin.com/in/lemon)
335
+ - [Linked In](http://www.linkedin.com/in/mattoriordan)
336
+
339
337
 
340
338
  License
341
339
  -------
342
340
 
343
- Copyright © 2016 Matthew O'Riordan, inc. It is free software, and may be redistributed under the terms specified in the LICENSE file.
341
+ Copyright © 2020 Matthew O'Riordan, inc. It is free software, and may be redistributed under the terms specified in the LICENSE file.
@@ -12,8 +12,12 @@ Gem::Specification.new do |s|
12
12
  s.summary = %q{Automatically create snapshots when Cucumber steps fail with Capybara and Rails}
13
13
  s.description = %q{When a Cucumber step fails, it is useful to create a screenshot image and HTML file of the current page}
14
14
  s.license = 'MIT'
15
-
16
- s.rubyforge_project = "capybara-screenshot"
15
+ s.metadata = {
16
+ "bug_tracker_uri" => "https://github.com/mattheworiordan/capybara-screenshot/issues",
17
+ "changelog_uri" => "https://github.com/mattheworiordan/capybara-screenshot/blob/master/CHANGELOG.md",
18
+ "documentation_uri" => "https://www.rubydoc.info/gems/capybara-screenshot/#{s.version}",
19
+ "source_code_uri" => "https://github.com/mattheworiordan/capybara-screenshot/tree/v#{s.version}",
20
+ }
17
21
 
18
22
  if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("1.9")
19
23
  s.add_dependency 'capybara', ['>= 1.0', '< 2']
@@ -1,4 +1,20 @@
1
1
  module Capybara
2
+ class << self
3
+ module ScreenshotOverrides
4
+ def using_session(name, &block)
5
+ original_session_name = Capybara.session_name
6
+ Capybara::Screenshot.final_session_name = name
7
+ super(name, &block)
8
+ Capybara::Screenshot.final_session_name = original_session_name
9
+ end
10
+
11
+ # No longer needed. Kept for backwards compatibility only.
12
+ alias_method :using_session_with_screenshot, :using_session
13
+ end
14
+
15
+ prepend ScreenshotOverrides
16
+ end
17
+
2
18
  module DSL
3
19
  # Adds class methods to Capybara module and gets mixed into
4
20
  # the current scope during Cucumber and RSpec tests
@@ -10,15 +26,17 @@ module Capybara
10
26
  def screenshot_and_open_image
11
27
  Capybara::Screenshot.screenshot_and_open_image
12
28
  end
29
+ end
13
30
 
14
- def using_session_with_screenshot(name,&blk)
15
- original_session_name = Capybara.session_name
16
- Capybara::Screenshot.final_session_name = name
17
- using_session_without_screenshot(name,&blk)
18
- Capybara::Screenshot.final_session_name = original_session_name
19
- end
31
+ module SessionScreenshotOverrides
32
+ def within_window(window_or_handle)
33
+ super
34
+ rescue Exception
35
+ Thread.current[:capybara_screenshot_offending_window] = window_or_handle
20
36
 
21
- alias_method :using_session_without_screenshot, :using_session
22
- alias_method :using_session, :using_session_with_screenshot
37
+ raise
38
+ end
23
39
  end
40
+
41
+ Session.prepend SessionScreenshotOverrides
24
42
  end
@@ -15,13 +15,20 @@ After do |scenario|
15
15
 
16
16
  # Trying to embed the screenshot into our output."
17
17
  if File.exist?(saver.screenshot_path)
18
- require "base64"
19
- #encode the image into it's base64 representation
20
18
  image = open(saver.screenshot_path, 'rb') {|io|io.read}
21
19
  saver.display_image
22
- #this will embed the image in the HTML report, embed() is defined in cucumber
23
- encoded_img = Base64.encode64(image)
24
- embed(encoded_img, 'image/png;base64', "Screenshot of the error")
20
+
21
+ # cucumber5 deprecates embed in favor of attach
22
+ if respond_to? :attach
23
+ #this will embed the image in the HTML report, attach() is defined in cucumber
24
+ attach(image, 'image/png')
25
+ else
26
+ #encode the image into it's base64 representation
27
+ require "base64"
28
+ encoded_img = Base64.encode64(image)
29
+ #this will embed the image in the HTML report, embed() is defined in cucumber
30
+ embed(encoded_img, 'image/png;base64', "Screenshot of the error")
31
+ end
25
32
  end
26
33
  end
27
34
  end
@@ -22,7 +22,7 @@ module Capybara
22
22
  end
23
23
 
24
24
  def link_to_screenshot(title, path)
25
- url = URI.escape("file://#{path}")
25
+ url = URI::DEFAULT_PARSER.escape("file://#{path}")
26
26
  title = CGI.escape_html(title)
27
27
  attributes = attributes_for_screenshot_link(url).map { |name, val| %{#{name}="#{CGI.escape_html(val)}"} }.join(" ")
28
28
  "<a #{attributes}>#{title}</a>"
@@ -90,6 +90,14 @@ RSpec.configure do |config|
90
90
  Capybara::Screenshot.final_session_name = nil
91
91
  end
92
92
 
93
+ # TODO: DRY refactor into a method?
94
+ # Add support for Rails system specs (previously only worked with feature specs)
95
+ config.after(type: :system) do |example_from_block_arg|
96
+ # RSpec 3 no longer defines `example`, but passes the example as block argument instead
97
+ example = config.respond_to?(:expose_current_running_example_as) ? example_from_block_arg : self.example
98
+
99
+ Capybara::Screenshot::RSpec.after_failed_example(example)
100
+ end
93
101
  config.after(type: :feature) do |example_from_block_arg|
94
102
  # RSpec 3 no longer defines `example`, but passes the example as block argument instead
95
103
  example = config.respond_to?(:expose_current_running_example_as) ? example_from_block_arg : self.example
@@ -11,6 +11,7 @@ module Capybara
11
11
  @saver = saver
12
12
  @s3_client = s3_client
13
13
  @bucket_name = bucket_name
14
+ @bucket_host = options[:bucket_host]
14
15
  @key_prefix = options[:key_prefix]
15
16
  @object_configuration = object_configuration
16
17
  end
@@ -49,9 +50,9 @@ module Capybara
49
50
  object_payload
50
51
  )
51
52
 
52
- s3_region = s3_client.get_bucket_location(bucket: bucket_name).location_constraint
53
+ host = bucket_host || determine_bucket_host
53
54
 
54
- send("#{type}_path=", "https://#{bucket_name}.s3-#{s3_region}.amazonaws.com/#{s3_upload_path}")
55
+ send("#{type}_path=", "https://#{host}/#{s3_upload_path}")
55
56
  end
56
57
  end
57
58
  end
@@ -68,9 +69,18 @@ module Capybara
68
69
  attr_reader :saver,
69
70
  :s3_client,
70
71
  :bucket_name,
72
+ :bucket_host,
71
73
  :object_configuration
72
74
  :key_prefix
73
75
 
76
+ ##
77
+ # Reads the bucket location using a S3 get_bucket_location request.
78
+ # Requires the +s3:GetBucketLocation+ policy.
79
+ def determine_bucket_host
80
+ s3_region = s3_client.get_bucket_location(bucket: bucket_name).location_constraint
81
+ "#{bucket_name}.s3-#{s3_region}.amazonaws.com"
82
+ end
83
+
74
84
  def save_and
75
85
  saver.save
76
86
 
@@ -27,20 +27,22 @@ module Capybara
27
27
 
28
28
  def save
29
29
  current_path do |path|
30
- if !path.empty?
31
- begin
32
- save_html if @html_save
33
- rescue StandardError => e
34
- warn "WARN: HTML source could not be saved. An exception is raised: #{e.inspect}."
30
+ within_offending_window do
31
+ if path.empty?
32
+ warn 'WARN: Screenshot could not be saved. `page.current_path` is empty.'
33
+ else
34
+ begin
35
+ save_html if @html_save
36
+ rescue StandardError => e
37
+ warn "WARN: HTML source could not be saved. An exception is raised: #{e.inspect}."
38
+ end
39
+
40
+ begin
41
+ save_screenshot
42
+ rescue StandardError => e
43
+ warn "WARN: Screenshot could not be saved. An exception is raised: #{e.inspect}."
44
+ end
35
45
  end
36
-
37
- begin
38
- save_screenshot
39
- rescue StandardError => e
40
- warn "WARN: Screenshot could not be saved. An exception is raised: #{e.inspect}."
41
- end
42
- else
43
- warn 'WARN: Screenshot could not be saved. `page.current_path` is empty.'
44
46
  end
45
47
  end
46
48
  end
@@ -49,9 +51,9 @@ module Capybara
49
51
  path = html_path
50
52
  clear_save_path do
51
53
  if Capybara::VERSION.match(/^\d+/)[0] == '1'
52
- capybara.save_page(page.body, "#{path}")
54
+ capybara.save_page(page.body, path.to_s)
53
55
  else
54
- capybara.save_page("#{path}")
56
+ capybara.save_page(path.to_s)
55
57
  end
56
58
  end
57
59
  @html_saved = true
@@ -132,13 +134,25 @@ module Capybara
132
134
  # which('ruby') #=> /usr/bin/ruby
133
135
  def which(cmd)
134
136
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
137
+
135
138
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
136
139
  exts.each { |ext|
137
140
  exe = File.join(path, "#{cmd}#{ext}")
138
141
  return exe if File.executable?(exe) && !File.directory?(exe)
139
142
  }
140
143
  end
141
- return nil
144
+
145
+ nil
146
+ end
147
+
148
+ def within_offending_window
149
+ return yield unless Thread.current[:capybara_screenshot_offending_window]
150
+
151
+ page.within_window(Thread.current[:capybara_screenshot_offending_window]) do
152
+ yield
153
+ end
154
+
155
+ Thread.current[:capybara_screenshot_offending_window] = nil
142
156
  end
143
157
  end
144
158
  end
@@ -1,5 +1,5 @@
1
1
  module Capybara
2
2
  module Screenshot
3
- VERSION = '1.0.22'
3
+ VERSION = '1.0.26'
4
4
  end
5
5
  end
@@ -190,6 +190,14 @@ Capybara::Screenshot.class_eval do
190
190
  :not_supported
191
191
  end
192
192
  end
193
+
194
+ register_driver(:apparition) do |driver, path|
195
+ driver.save_screenshot(path)
196
+ end
197
+
198
+ register_driver(:cuprite) do |driver, path|
199
+ driver.render(path, :full => true)
200
+ end
193
201
  end
194
202
 
195
203
  # Register filename prefix formatters
@@ -26,7 +26,7 @@ describe "Using Capybara::Screenshot with Cucumber" do
26
26
 
27
27
  write_file('features/cucumber.feature', code)
28
28
 
29
- run_simple_with_retry cmd, false
29
+ run_simple_with_retry cmd
30
30
 
31
31
  expect(last_command_started.output).to_not match(/failed|failure/i) if options[:assert_all_passed]
32
32
  end
@@ -22,7 +22,7 @@ describe "Using Capybara::Screenshot with MiniTest" do
22
22
  RUBY
23
23
 
24
24
  cmd = 'bundle exec ruby test_failure.rb'
25
- run_simple_with_retry cmd, false
25
+ run_simple_with_retry cmd
26
26
  expect(last_command_started.output).to match %r{Unable to find (visible )?link or button "you'll never find me"}
27
27
  end
28
28
 
@@ -28,7 +28,7 @@ describe "Using Capybara::Screenshot with Test::Unit" do
28
28
  RUBY
29
29
 
30
30
  cmd = "bundle exec ruby #{integration_path}/test_failure.rb"
31
- run_simple_with_retry cmd, false
31
+ run_simple_with_retry cmd
32
32
  expect(last_command_started.output).to match %r{Unable to find (visible )?link or button "you'll never find me"}
33
33
  end
34
34
 
@@ -31,7 +31,7 @@ describe Capybara::Screenshot::RSpec, :type => :aruba do
31
31
  RUBY
32
32
 
33
33
  cmd = cmd_with_format(options[:format])
34
- run_simple_with_retry cmd, false
34
+ run_simple_with_retry cmd
35
35
 
36
36
  expect(last_command_started.output).to match('0 failures') if options[:assert_all_passed]
37
37
  end
@@ -116,7 +116,24 @@ describe Capybara::Screenshot::RSpec, :type => :aruba do
116
116
  end
117
117
  end
118
118
  RUBY
119
- expect('tmp/screenshot.html').to have_file_content(/is/)
119
+ expect('tmp/screenshot.html').to have_file_content(/This is a different page/)
120
+ end
121
+
122
+ it 'saves a screenshot for the correct session for failures Capybara.using_session' do
123
+ run_failing_case <<-RUBY, %r{Unable to find (visible )?link or button "you'll never find me"}
124
+ feature 'screenshot with failure' do
125
+ scenario 'click on a missing link' do
126
+ visit '/'
127
+ expect(page.body).to include('This is the root page')
128
+ Capybara.using_session :different_session do
129
+ visit '/different_page'
130
+ expect(page.body).to include('This is a different page')
131
+ click_on "you'll never find me"
132
+ end
133
+ end
134
+ end
135
+ RUBY
136
+ expect('tmp/screenshot.html').to have_file_content(/This is a different page/)
120
137
  end
121
138
 
122
139
  context 'pruning' do
@@ -12,7 +12,7 @@ describe "Using Capybara::Screenshot with Spinach" do
12
12
 
13
13
  write_file('spinach.feature', code)
14
14
  cmd = 'bundle exec spinach -f .'
15
- run_simple_with_retry cmd, false
15
+ run_simple_with_retry cmd
16
16
  expect(last_command_started.output).to match(failure_message)
17
17
  end
18
18
 
@@ -41,11 +41,11 @@ module CommonSetup
41
41
  end
42
42
  end
43
43
 
44
- def run_simple_with_retry(*args)
45
- run_simple(*args)
44
+ def run_simple_with_retry(cmd, fail_on_error: false)
45
+ run_command_and_stop(cmd, fail_on_error: fail_on_error)
46
46
  rescue ChildProcess::TimeoutError => e
47
- puts "run_simple(#{args.join(', ')}) failed. Will retry once. `#{e.message}`"
48
- run_simple(*args)
47
+ puts "run_command_and_stop(#{cmd}, fail_on_error: #{fail_on_error}) failed. Will retry once. `#{e.message}`"
48
+ run_command_and_stop(cmd, fail_on_error: fail_on_error)
49
49
  end
50
50
 
51
51
  def configure_prune_strategy(strategy)
@@ -26,6 +26,19 @@ describe Capybara do
26
26
  }.to raise_exception ::RSpec::Expectations::ExpectationNotMetError
27
27
  end
28
28
  end
29
+
30
+ describe 'Capybara.using_session' do
31
+ include Capybara::DSL
32
+
33
+ it 'saves the name of the final session' do
34
+ expect(Capybara::Screenshot).to receive(:final_session_name=).with(:different_session)
35
+ expect {
36
+ Capybara.using_session :different_session do
37
+ expect(0).to eq 1
38
+ end
39
+ }.to raise_exception ::RSpec::Expectations::ExpectationNotMetError
40
+ end
41
+ end
29
42
  end
30
43
 
31
44
  describe 'final_session_name' do
@@ -5,10 +5,11 @@ describe Capybara::Screenshot::S3Saver do
5
5
  let(:saver) { double('saver') }
6
6
  let(:bucket_name) { double('bucket_name') }
7
7
  let(:s3_object_configuration) { {} }
8
+ let(:options) { {} }
8
9
  let(:s3_client) { double('s3_client') }
9
10
  let(:key_prefix){ "some/path/" }
10
11
 
11
- let(:s3_saver) { described_class.new(saver, s3_client, bucket_name, s3_object_configuration) }
12
+ let(:s3_saver) { described_class.new(saver, s3_client, bucket_name, s3_object_configuration, options) }
12
13
  let(:s3_saver_with_key_prefix) { described_class.new(saver, s3_client, bucket_name, s3_object_configuration, key_prefix: key_prefix) }
13
14
 
14
15
  let(:region) { double('region') }
@@ -104,6 +105,20 @@ describe Capybara::Screenshot::S3Saver do
104
105
  allow(saver).to receive(:save)
105
106
  end
106
107
 
108
+ context 'providing a bucket_host' do
109
+ let(:options) { { bucket_host: 'some other location' } }
110
+
111
+ it 'does not request the bucket location' do
112
+ screenshot_path = '/baz/bim.jpg'
113
+
114
+ screenshot_file = double('screenshot_file')
115
+
116
+ expect(s3_saver).not_to receive(:determine_bucket_host)
117
+
118
+ s3_saver.save
119
+ end
120
+ end
121
+
107
122
  it 'calls save on the underlying saver' do
108
123
  expect(saver).to receive(:save)
109
124
 
@@ -125,6 +140,8 @@ describe Capybara::Screenshot::S3Saver do
125
140
  body: html_file
126
141
  )
127
142
 
143
+ expect(s3_saver).to receive(:determine_bucket_host).and_call_original
144
+
128
145
  s3_saver.save
129
146
  end
130
147
 
@@ -298,6 +298,19 @@ describe Capybara::Screenshot::Saver do
298
298
  end
299
299
  end
300
300
 
301
+ describe "with cuprite driver" do
302
+ before do
303
+ allow(capybara_mock).to receive(:current_driver).and_return(:cuprite)
304
+ end
305
+
306
+ it 'saves driver render with :full => true' do
307
+ expect(driver_mock).to receive(:render).with(screenshot_path, {:full => true})
308
+
309
+ saver.save
310
+ expect(saver).to be_screenshot_saved
311
+ end
312
+ end
313
+
301
314
  describe "with webkit driver" do
302
315
  before do
303
316
  allow(capybara_mock).to receive(:current_driver).and_return(:webkit)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara-screenshot
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.22
4
+ version: 1.0.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew O'Riordan
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-21 00:00:00.000000000 Z
11
+ date: 2022-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara
@@ -240,8 +240,12 @@ files:
240
240
  homepage: http://github.com/mattheworiordan/capybara-screenshot
241
241
  licenses:
242
242
  - MIT
243
- metadata: {}
244
- post_install_message:
243
+ metadata:
244
+ bug_tracker_uri: https://github.com/mattheworiordan/capybara-screenshot/issues
245
+ changelog_uri: https://github.com/mattheworiordan/capybara-screenshot/blob/master/CHANGELOG.md
246
+ documentation_uri: https://www.rubydoc.info/gems/capybara-screenshot/1.0.26
247
+ source_code_uri: https://github.com/mattheworiordan/capybara-screenshot/tree/v1.0.26
248
+ post_install_message:
245
249
  rdoc_options: []
246
250
  require_paths:
247
251
  - lib
@@ -256,9 +260,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
256
260
  - !ruby/object:Gem::Version
257
261
  version: '0'
258
262
  requirements: []
259
- rubyforge_project: capybara-screenshot
260
- rubygems_version: 2.4.8
261
- signing_key:
263
+ rubygems_version: 3.0.3
264
+ signing_key:
262
265
  specification_version: 4
263
266
  summary: Automatically create snapshots when Cucumber steps fail with Capybara and
264
267
  Rails