capybara-screenshot 1.0.20 → 1.0.25
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +4 -3
- data/CHANGELOG.md +25 -0
- data/Gemfile +1 -1
- data/README.md +36 -38
- data/capybara-screenshot.gemspec +10 -3
- data/lib/capybara-screenshot.rb +11 -3
- data/lib/capybara-screenshot/callbacks.rb +2 -2
- data/lib/capybara-screenshot/capybara.rb +16 -12
- data/lib/capybara-screenshot/cucumber.rb +7 -1
- data/lib/capybara-screenshot/minitest.rb +1 -1
- data/lib/capybara-screenshot/pruner.rb +4 -1
- data/lib/capybara-screenshot/rspec.rb +8 -0
- data/lib/capybara-screenshot/rspec/base_reporter.rb +1 -2
- data/lib/capybara-screenshot/rspec/html_embed_reporter.rb +14 -3
- data/lib/capybara-screenshot/rspec/text_reporter.rb +2 -2
- data/lib/capybara-screenshot/s3_saver.rb +22 -4
- data/lib/capybara-screenshot/saver.rb +8 -6
- data/lib/capybara-screenshot/version.rb +1 -1
- data/spec/cucumber/cucumber_spec.rb +4 -4
- data/spec/feature/minitest_spec.rb +2 -2
- data/spec/feature/testunit_spec.rb +3 -3
- data/spec/rspec/rspec_spec.rb +21 -4
- data/spec/spinach/spinach_spec.rb +4 -4
- data/spec/support/common_setup.rb +4 -4
- data/spec/unit/capybara_spec.rb +13 -0
- data/spec/unit/rspec_reporters/html_embed_reporter_spec.rb +13 -0
- data/spec/unit/rspec_reporters/text_reporter_spec.rb +6 -6
- data/spec/unit/s3_saver_spec.rb +24 -2
- data/spec/unit/saver_spec.rb +13 -0
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8539dcf08bbfb122dfb190cd76f82361373b4016888d02e65daedf42998e7cd2
|
4
|
+
data.tar.gz: bb64e6eb25278f8564a694784b21f9f38d3c550cf6cd2949fe5b5dd2adf5b916
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1b62365f1e18a17bc4e0d0443bce7194dd7fe9fdbe846df3ea68b45583d452e6fe0047611f8639eb43bc015307de9f993a1485164ddf502879801fd213f9031
|
7
|
+
data.tar.gz: 5a599e20a7684bf4045c2cb318099af8a9385705e83afe342fe756bd592dfc762816dcd54a3946a370b84805dc3d65c8ce2e5fb927c3673256e4c362131611aa
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,28 @@
|
|
1
|
+
4 Oct 2020 - 1.0.24 -> 1.0.25
|
2
|
+
|
3
|
+
* [Fix Cucumber 5 deprecation warnings](https://github.com/mattheworiordan/capybara-screenshot/pull/274)
|
4
|
+
* [Add support for Cuprite driver](https://github.com/mattheworiordan/capybara-screenshot/pull/270)
|
5
|
+
* [Rails system spec compatibility](https://github.com/mattheworiordan/capybara-screenshot/pull/264)
|
6
|
+
|
7
|
+
24 Nov 2019 - 1.0.23 -> 1.0.24
|
8
|
+
|
9
|
+
* [Support Apparition driver](https://github.com/mattheworiordan/capybara-screenshot/commit/273317b241d1d1d8600b32fad998742894424f3b)
|
10
|
+
|
11
|
+
10 Jun 2019 - 1.0.22 -> 1.0.23
|
12
|
+
|
13
|
+
* [Support for Capybara sessions implicitly](https://github.com/mattheworiordan/capybara-screenshot/pull/255). Thanks https://github.com/TylerRick
|
14
|
+
* [Support for S3 bucket host configuration](https://github.com/mattheworiordan/capybara-screenshot/pull/252). Thanks https://github.com/machty
|
15
|
+
|
16
|
+
21 Oct 2018 - 1.0.21 -> 1.0.22
|
17
|
+
|
18
|
+
* [Support for S3 URL in HTML screenshots](https://github.com/mattheworiordan/capybara-screenshot/pull/239)
|
19
|
+
* [Fix for partial Rails environments](https://github.com/mattheworiordan/capybara-screenshot/pull/238)
|
20
|
+
* [Capybara 3 support in CI](https://github.com/mattheworiordan/capybara-screenshot/pull/236)
|
21
|
+
|
22
|
+
03 May 2018 - 1.0.20 -> 1.0.21
|
23
|
+
|
24
|
+
* [Bug fix: Fix Ruby version compares in Gemspec](https://github.com/mattheworiordan/capybara-screenshot/pull/231)
|
25
|
+
|
1
26
|
03 May 2018 - 1.0.19 -> 1.0.20
|
2
27
|
|
3
28
|
* [Bug fix: Only take screenshots for feature tests](https://github.com/mattheworiordan/capybara-screenshot/pull/223)
|
data/Gemfile
CHANGED
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
|
8
|
+
#### Capture a screenshot for every test failure automatically!
|
9
9
|
|
10
|
-
`capybara-screenshot` used with [Capybara](https://github.com/jnicklas/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
|
-
|
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.
|
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
|
-
|
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
|
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,
|
90
|
-
|
91
|
-
can be
|
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
|
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
|
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
|
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
|
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
|
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/
|
335
|
+
- [Linked In](http://www.linkedin.com/in/mattoriordan)
|
336
|
+
|
339
337
|
|
340
338
|
License
|
341
339
|
-------
|
342
340
|
|
343
|
-
Copyright ©
|
341
|
+
Copyright © 2020 Matthew O'Riordan, inc. It is free software, and may be redistributed under the terms specified in the LICENSE file.
|
data/capybara-screenshot.gemspec
CHANGED
@@ -12,14 +12,21 @@ 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
|
+
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
|
+
}
|
15
21
|
|
16
|
-
|
17
|
-
|
18
|
-
if RUBY_VERSION < "1.9"
|
22
|
+
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("1.9")
|
19
23
|
s.add_dependency 'capybara', ['>= 1.0', '< 2']
|
24
|
+
elsif Gem::Version.new(RUBY_VERSION) <= Gem::Version.new("2.2.2")
|
25
|
+
s.add_dependency 'capybara', ['>= 1.0', '< 3']
|
20
26
|
else
|
21
27
|
s.add_dependency 'capybara', ['>= 1.0', '< 4']
|
22
28
|
end
|
29
|
+
|
23
30
|
s.add_dependency 'launchy'
|
24
31
|
|
25
32
|
s.add_development_dependency 'rspec'
|
data/lib/capybara-screenshot.rb
CHANGED
@@ -58,7 +58,7 @@ module Capybara
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def self.capybara_root
|
61
|
-
@capybara_root ||= if defined?(::Rails) && ::Rails.root.present?
|
61
|
+
@capybara_root ||= if defined?(::Rails) && ::Rails.respond_to?(:root) && ::Rails.root.present?
|
62
62
|
::Rails.root.join capybara_tmp_path
|
63
63
|
elsif defined?(Padrino)
|
64
64
|
File.expand_path(capybara_tmp_path, Padrino.root)
|
@@ -106,11 +106,11 @@ module Capybara
|
|
106
106
|
end
|
107
107
|
|
108
108
|
def self.after_save_html &block
|
109
|
-
Saver.after_save_html
|
109
|
+
Saver.after_save_html(&block)
|
110
110
|
end
|
111
111
|
|
112
112
|
def self.after_save_screenshot &block
|
113
|
-
Saver.after_save_screenshot
|
113
|
+
Saver.after_save_screenshot(&block)
|
114
114
|
end
|
115
115
|
|
116
116
|
private
|
@@ -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
|
@@ -4,7 +4,7 @@ module Capybara
|
|
4
4
|
class CallbackSet < Array
|
5
5
|
def call *args
|
6
6
|
each do |callback|
|
7
|
-
callback.call
|
7
|
+
callback.call(*args)
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
@@ -24,7 +24,7 @@ module Capybara
|
|
24
24
|
|
25
25
|
def run_callbacks name, *args
|
26
26
|
if cb_set = callbacks[name]
|
27
|
-
cb_set.call
|
27
|
+
cb_set.call(*args)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -1,6 +1,20 @@
|
|
1
|
-
require "capybara-screenshot"
|
2
|
-
|
3
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
|
+
|
4
18
|
module DSL
|
5
19
|
# Adds class methods to Capybara module and gets mixed into
|
6
20
|
# the current scope during Cucumber and RSpec tests
|
@@ -12,15 +26,5 @@ module Capybara
|
|
12
26
|
def screenshot_and_open_image
|
13
27
|
Capybara::Screenshot.screenshot_and_open_image
|
14
28
|
end
|
15
|
-
|
16
|
-
def using_session_with_screenshot(name,&blk)
|
17
|
-
original_session_name = Capybara.session_name
|
18
|
-
Capybara::Screenshot.final_session_name = name
|
19
|
-
using_session_without_screenshot(name,&blk)
|
20
|
-
Capybara::Screenshot.final_session_name = original_session_name
|
21
|
-
end
|
22
|
-
|
23
|
-
alias_method :using_session_without_screenshot, :using_session
|
24
|
-
alias_method :using_session, :using_session_with_screenshot
|
25
29
|
end
|
26
30
|
end
|
@@ -21,7 +21,13 @@ After do |scenario|
|
|
21
21
|
saver.display_image
|
22
22
|
#this will embed the image in the HTML report, embed() is defined in cucumber
|
23
23
|
encoded_img = Base64.encode64(image)
|
24
|
-
|
24
|
+
|
25
|
+
# cucumber5 deprecates embed in favor of attach
|
26
|
+
if respond_to? :attach
|
27
|
+
attach(encoded_img, 'image/png')
|
28
|
+
else
|
29
|
+
embed(encoded_img, 'image/png;base64', "Screenshot of the error")
|
30
|
+
end
|
25
31
|
end
|
26
32
|
end
|
27
33
|
end
|
@@ -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
|
@@ -3,7 +3,7 @@ module Capybara
|
|
3
3
|
module RSpec
|
4
4
|
module BaseReporter
|
5
5
|
|
6
|
-
# Automatically set up method aliases (very much like ActiveSupport's `alias_method_chain`)
|
6
|
+
# Automatically set up method aliases (very much like ActiveSupport's `alias_method_chain`)
|
7
7
|
# when the module gets included.
|
8
8
|
def enhance_with_screenshot(method)
|
9
9
|
with_method, without_method = "#{method}_with_screenshot", "#{method}_without_screenshot"
|
@@ -14,7 +14,6 @@ module Capybara
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
17
|
-
|
18
17
|
end
|
19
18
|
end
|
20
19
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'capybara-screenshot/rspec/base_reporter'
|
2
2
|
require 'base64'
|
3
|
+
require 'uri'
|
3
4
|
|
4
5
|
module Capybara
|
5
6
|
module Screenshot
|
@@ -13,12 +14,22 @@ module Capybara
|
|
13
14
|
example = @failed_examples.last
|
14
15
|
# Ignores saved html file, only saved image will be embedded (if present)
|
15
16
|
if (screenshot = example.metadata[:screenshot]) && screenshot[:image]
|
16
|
-
|
17
|
-
encoded_img = Base64.encode64(image)
|
18
|
-
result += "<img src='data:image/png;base64,#{encoded_img}' style='display: block'>"
|
17
|
+
result += "<img src='#{image_tag_source(screenshot[:image])}' style='display: block'>"
|
19
18
|
end
|
20
19
|
result
|
21
20
|
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def image_tag_source(path)
|
25
|
+
if URI.regexp(%w[http https]) =~ path
|
26
|
+
path
|
27
|
+
else
|
28
|
+
image = File.binread(path)
|
29
|
+
encoded_img = Base64.encode64(image)
|
30
|
+
"data:image/png;base64,#{encoded_img}"
|
31
|
+
end
|
32
|
+
end
|
22
33
|
end
|
23
34
|
end
|
24
35
|
end
|
@@ -26,8 +26,8 @@ module Capybara
|
|
26
26
|
private
|
27
27
|
def output_screenshot_info(example)
|
28
28
|
return unless (screenshot = example.metadata[:screenshot])
|
29
|
-
output.puts(long_padding + CapybaraScreenshot::Helpers.yellow("HTML screenshot:
|
30
|
-
output.puts(long_padding + CapybaraScreenshot::Helpers.yellow("Image screenshot:
|
29
|
+
output.puts(long_padding + CapybaraScreenshot::Helpers.yellow("HTML screenshot: #{screenshot[:html]}")) if screenshot[:html]
|
30
|
+
output.puts(long_padding + CapybaraScreenshot::Helpers.yellow("Image screenshot: #{screenshot[:image]}")) if screenshot[:image]
|
31
31
|
end
|
32
32
|
|
33
33
|
def long_padding
|
@@ -5,10 +5,13 @@ module Capybara
|
|
5
5
|
class S3Saver
|
6
6
|
DEFAULT_REGION = 'us-east-1'
|
7
7
|
|
8
|
+
attr_accessor :html_path, :screenshot_path
|
9
|
+
|
8
10
|
def initialize(saver, s3_client, bucket_name, object_configuration, options={})
|
9
11
|
@saver = saver
|
10
12
|
@s3_client = s3_client
|
11
13
|
@bucket_name = bucket_name
|
14
|
+
@bucket_host = options[:bucket_host]
|
12
15
|
@key_prefix = options[:key_prefix]
|
13
16
|
@object_configuration = object_configuration
|
14
17
|
end
|
@@ -31,11 +34,13 @@ module Capybara
|
|
31
34
|
end
|
32
35
|
|
33
36
|
def save_and_upload_screenshot
|
34
|
-
save_and do |local_file_path|
|
37
|
+
save_and do |type, local_file_path|
|
35
38
|
File.open(local_file_path) do |file|
|
39
|
+
s3_upload_path = "#{@key_prefix}#{File.basename(local_file_path)}"
|
40
|
+
|
36
41
|
object_payload = {
|
37
42
|
bucket: bucket_name,
|
38
|
-
key:
|
43
|
+
key: s3_upload_path,
|
39
44
|
body: file
|
40
45
|
}
|
41
46
|
|
@@ -44,6 +49,10 @@ module Capybara
|
|
44
49
|
s3_client.put_object(
|
45
50
|
object_payload
|
46
51
|
)
|
52
|
+
|
53
|
+
host = bucket_host || determine_bucket_host
|
54
|
+
|
55
|
+
send("#{type}_path=", "https://#{host}/#{s3_upload_path}")
|
47
56
|
end
|
48
57
|
end
|
49
58
|
end
|
@@ -60,14 +69,23 @@ module Capybara
|
|
60
69
|
attr_reader :saver,
|
61
70
|
:s3_client,
|
62
71
|
:bucket_name,
|
72
|
+
:bucket_host,
|
63
73
|
:object_configuration
|
64
74
|
:key_prefix
|
65
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
|
+
|
66
84
|
def save_and
|
67
85
|
saver.save
|
68
86
|
|
69
|
-
yield(saver.html_path) if block_given? && saver.html_saved?
|
70
|
-
yield(saver.screenshot_path) if block_given? && saver.screenshot_saved?
|
87
|
+
yield(:html, saver.html_path) if block_given? && saver.html_saved?
|
88
|
+
yield(:screenshot, saver.screenshot_path) if block_given? && saver.screenshot_saved?
|
71
89
|
end
|
72
90
|
end
|
73
91
|
end
|
@@ -27,7 +27,9 @@ module Capybara
|
|
27
27
|
|
28
28
|
def save
|
29
29
|
current_path do |path|
|
30
|
-
if
|
30
|
+
if path.empty?
|
31
|
+
warn 'WARN: Screenshot could not be saved. `page.current_path` is empty.'
|
32
|
+
else
|
31
33
|
begin
|
32
34
|
save_html if @html_save
|
33
35
|
rescue StandardError => e
|
@@ -39,8 +41,6 @@ module Capybara
|
|
39
41
|
rescue StandardError => e
|
40
42
|
warn "WARN: Screenshot could not be saved. An exception is raised: #{e.inspect}."
|
41
43
|
end
|
42
|
-
else
|
43
|
-
warn 'WARN: Screenshot could not be saved. `page.current_path` is empty.'
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
@@ -49,9 +49,9 @@ module Capybara
|
|
49
49
|
path = html_path
|
50
50
|
clear_save_path do
|
51
51
|
if Capybara::VERSION.match(/^\d+/)[0] == '1'
|
52
|
-
capybara.save_page(page.body,
|
52
|
+
capybara.save_page(page.body, path.to_s)
|
53
53
|
else
|
54
|
-
capybara.save_page(
|
54
|
+
capybara.save_page(path.to_s)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
@html_saved = true
|
@@ -132,13 +132,15 @@ module Capybara
|
|
132
132
|
# which('ruby') #=> /usr/bin/ruby
|
133
133
|
def which(cmd)
|
134
134
|
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
135
|
+
|
135
136
|
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
136
137
|
exts.each { |ext|
|
137
138
|
exe = File.join(path, "#{cmd}#{ext}")
|
138
139
|
return exe if File.executable?(exe) && !File.directory?(exe)
|
139
140
|
}
|
140
141
|
end
|
141
|
-
|
142
|
+
|
143
|
+
nil
|
142
144
|
end
|
143
145
|
end
|
144
146
|
end
|
@@ -26,13 +26,13 @@ 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
|
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
|
33
33
|
|
34
34
|
it 'saves a screenshot on failure' do
|
35
|
-
run_failing_case %q{Unable to find visible link or button "you'll never find me"}, <<-CUCUMBER
|
35
|
+
run_failing_case %q{Unable to find (visible )?link or button "you'll never find me"}, <<-CUCUMBER
|
36
36
|
Feature: Failure
|
37
37
|
Scenario: Failure
|
38
38
|
Given I visit "/"
|
@@ -52,7 +52,7 @@ describe "Using Capybara::Screenshot with Cucumber" do
|
|
52
52
|
end
|
53
53
|
|
54
54
|
it 'saves a screenshot for the correct session for failures using_session' do
|
55
|
-
run_failing_case(%q{Unable to find visible link or button "you'll never find me"}, <<-CUCUMBER)
|
55
|
+
run_failing_case(%q{Unable to find (visible )?link or button "you'll never find me"}, <<-CUCUMBER)
|
56
56
|
Feature: Failure
|
57
57
|
Scenario: Failure in different session
|
58
58
|
Given I visit "/"
|
@@ -68,7 +68,7 @@ describe "Using Capybara::Screenshot with Cucumber" do
|
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'on failure it prunes previous screenshots when strategy is set' do
|
71
|
-
run_failing_case %q{Unable to find visible link or button "you'll never find me"}, <<-CUCUMBER
|
71
|
+
run_failing_case %q{Unable to find (visible )?link or button "you'll never find me"}, <<-CUCUMBER
|
72
72
|
Feature: Prune
|
73
73
|
Scenario: Screenshots are pruned if strategy is set
|
74
74
|
Given I visit "/"
|
@@ -22,8 +22,8 @@ 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
|
26
|
-
expect(last_command_started.output).to
|
25
|
+
run_simple_with_retry cmd
|
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
|
|
29
29
|
it 'saves a screenshot on failure' do
|
@@ -14,7 +14,7 @@ describe "Using Capybara::Screenshot with Test::Unit" do
|
|
14
14
|
|
15
15
|
#{setup_test_app}
|
16
16
|
Capybara::Screenshot.register_filename_prefix_formatter(:testunit) do | fault |
|
17
|
-
raise "expected fault" unless fault.exception.message.
|
17
|
+
raise "expected fault" unless fault.exception.message.match %r{Unable to find (visible )?link or button "you'll never find me"}
|
18
18
|
'my_screenshot'
|
19
19
|
end
|
20
20
|
|
@@ -28,8 +28,8 @@ 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
|
32
|
-
expect(last_command_started.output).to
|
31
|
+
run_simple_with_retry cmd
|
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
|
|
35
35
|
it "saves a screenshot on failure for any test in path 'test/integration'" do
|
data/spec/rspec/rspec_spec.rb
CHANGED
@@ -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
|
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
|
@@ -41,7 +41,7 @@ describe Capybara::Screenshot::RSpec, :type => :aruba do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'saves a screenshot when browser action fails' do
|
44
|
-
run_failing_case <<-RUBY, %
|
44
|
+
run_failing_case <<-RUBY, %r{Unable to find (visible )?link or button "you'll never find me"}
|
45
45
|
feature 'screenshot with failure' do
|
46
46
|
scenario 'click on a missing link' do
|
47
47
|
visit '/'
|
@@ -103,7 +103,7 @@ describe Capybara::Screenshot::RSpec, :type => :aruba do
|
|
103
103
|
end
|
104
104
|
|
105
105
|
it 'saves a screenshot for the correct session for failures using_session' do
|
106
|
-
run_failing_case <<-RUBY, %
|
106
|
+
run_failing_case <<-RUBY, %r{Unable to find (visible )?link or button "you'll never find me"}
|
107
107
|
feature 'screenshot with failure' do
|
108
108
|
scenario 'click on a missing link' do
|
109
109
|
visit '/'
|
@@ -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,12 +12,12 @@ 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
|
15
|
+
run_simple_with_retry cmd
|
16
16
|
expect(last_command_started.output).to match(failure_message)
|
17
17
|
end
|
18
18
|
|
19
19
|
it "saves a screenshot on failure" do
|
20
|
-
run_failing_case(%q{Unable to find visible link or button "you'll never find me"}, <<-GHERKIN)
|
20
|
+
run_failing_case(%q{Unable to find (visible )?link or button "you'll never find me"}, <<-GHERKIN)
|
21
21
|
Feature: Failure
|
22
22
|
Scenario: Failure
|
23
23
|
Given I visit "/"
|
@@ -37,7 +37,7 @@ describe "Using Capybara::Screenshot with Spinach" do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
it "saves a screenshot for the correct session for failures using_session" do
|
40
|
-
run_failing_case(%q{Unable to find visible link or button "you'll never find me"}, <<-GHERKIN)
|
40
|
+
run_failing_case(%q{Unable to find (visible )?link or button "you'll never find me"}, <<-GHERKIN)
|
41
41
|
Feature: Failure
|
42
42
|
Scenario: Failure in different session
|
43
43
|
Given I visit "/"
|
@@ -49,7 +49,7 @@ describe "Using Capybara::Screenshot with Spinach" do
|
|
49
49
|
it 'on failure it prunes previous screenshots when strategy is set' do
|
50
50
|
create_screenshot_for_pruning
|
51
51
|
configure_prune_strategy :last_run
|
52
|
-
run_failing_case(%q{Unable to find visible link or button "you'll never find me"}, <<-GHERKIN)
|
52
|
+
run_failing_case(%q{Unable to find (visible )?link or button "you'll never find me"}, <<-GHERKIN)
|
53
53
|
Feature: Failure
|
54
54
|
Scenario: Failure
|
55
55
|
Given I visit "/"
|
@@ -41,11 +41,11 @@ module CommonSetup
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
def run_simple_with_retry(
|
45
|
-
|
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 "
|
48
|
-
|
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)
|
data/spec/unit/capybara_spec.rb
CHANGED
@@ -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
|
@@ -15,4 +15,17 @@ describe Capybara::Screenshot::RSpec::HtmlEmbedReporter do
|
|
15
15
|
expect(content_without_styles).to eql("original content<img src='data:image/png;base64,#{encoded_image_data}'>")
|
16
16
|
end
|
17
17
|
end
|
18
|
+
|
19
|
+
context 'when an image was saved to s3' do
|
20
|
+
let(:s3_image_url) { "http://s3.amazon.com/path/to/image" }
|
21
|
+
|
22
|
+
before do
|
23
|
+
set_example double("example", metadata: {screenshot: {image: s3_image_url}})
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'embeds the image URL into the content' do
|
27
|
+
content_without_styles = @reporter.extra_failure_content(nil).gsub(/ ?style='.*?' ?/, "")
|
28
|
+
expect(content_without_styles).to eql("original content<img src='#{s3_image_url}'>")
|
29
|
+
end
|
30
|
+
end
|
18
31
|
end
|
@@ -64,20 +64,20 @@ describe Capybara::Screenshot::RSpec::TextReporter do
|
|
64
64
|
end
|
65
65
|
|
66
66
|
context 'when a html file was saved' do
|
67
|
-
let(:example) { example_failed_method_argument_double(screenshot: { html: "path/to/html" }) }
|
67
|
+
let(:example) { example_failed_method_argument_double(screenshot: { html: "/path/to/html" }) }
|
68
68
|
|
69
69
|
it 'appends the html file path to the original output' do
|
70
70
|
@reporter.send(example_failed_method, example)
|
71
|
-
expect(@reporter.output.string).to eql("original failure info\n #{CapybaraScreenshot::Helpers.yellow("HTML screenshot:
|
71
|
+
expect(@reporter.output.string).to eql("original failure info\n #{CapybaraScreenshot::Helpers.yellow("HTML screenshot: /path/to/html")}\n")
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
75
|
context 'when a html file and an image were saved' do
|
76
|
-
let(:example) { example_failed_method_argument_double(screenshot: { html: "path/to/html", image: "path/to/image" }) }
|
76
|
+
let(:example) { example_failed_method_argument_double(screenshot: { html: "/path/to/html", image: "/path/to/image" }) }
|
77
77
|
|
78
78
|
it 'appends the image path to the original output' do
|
79
79
|
@reporter.send(example_failed_method, example)
|
80
|
-
expect(@reporter.output.string).to eql("original failure info\n #{CapybaraScreenshot::Helpers.yellow("HTML screenshot:
|
80
|
+
expect(@reporter.output.string).to eql("original failure info\n #{CapybaraScreenshot::Helpers.yellow("HTML screenshot: /path/to/html")}\n #{CapybaraScreenshot::Helpers.yellow("Image screenshot: /path/to/image")}\n")
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
@@ -91,8 +91,8 @@ describe Capybara::Screenshot::RSpec::TextReporter do
|
|
91
91
|
end
|
92
92
|
old_reporter = old_reporter_class.new
|
93
93
|
old_reporter.singleton_class.send :include, described_class
|
94
|
-
example = example_failed_method_argument_double(screenshot: { html: "path/to/html" })
|
94
|
+
example = example_failed_method_argument_double(screenshot: { html: "/path/to/html" })
|
95
95
|
old_reporter.send(example_failed_method, example)
|
96
|
-
expect(old_reporter.output.string).to eql("original failure info\n #{CapybaraScreenshot::Helpers.yellow("HTML screenshot:
|
96
|
+
expect(old_reporter.output.string).to eql("original failure info\n #{CapybaraScreenshot::Helpers.yellow("HTML screenshot: /path/to/html")}\n")
|
97
97
|
end
|
98
98
|
end
|
data/spec/unit/s3_saver_spec.rb
CHANGED
@@ -5,12 +5,19 @@ 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
|
|
15
|
+
let(:region) { double('region') }
|
16
|
+
|
17
|
+
before do
|
18
|
+
allow(s3_client).to receive(:get_bucket_location).and_return(double(:bucket_location_response, location_constraint: region))
|
19
|
+
end
|
20
|
+
|
14
21
|
describe '.new_with_configuration' do
|
15
22
|
let(:access_key_id) { double('access_key_id') }
|
16
23
|
let(:secret_access_key) { double('secret_access_key') }
|
@@ -21,7 +28,6 @@ describe Capybara::Screenshot::S3Saver do
|
|
21
28
|
}
|
22
29
|
}
|
23
30
|
|
24
|
-
let(:region) { double('region') }
|
25
31
|
let(:s3_client_credentials) {
|
26
32
|
s3_client_credentials_using_defaults.merge(region: region)
|
27
33
|
}
|
@@ -99,6 +105,20 @@ describe Capybara::Screenshot::S3Saver do
|
|
99
105
|
allow(saver).to receive(:save)
|
100
106
|
end
|
101
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
|
+
|
102
122
|
it 'calls save on the underlying saver' do
|
103
123
|
expect(saver).to receive(:save)
|
104
124
|
|
@@ -120,6 +140,8 @@ describe Capybara::Screenshot::S3Saver do
|
|
120
140
|
body: html_file
|
121
141
|
)
|
122
142
|
|
143
|
+
expect(s3_saver).to receive(:determine_bucket_host).and_call_original
|
144
|
+
|
123
145
|
s3_saver.save
|
124
146
|
end
|
125
147
|
|
data/spec/unit/saver_spec.rb
CHANGED
@@ -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.
|
4
|
+
version: 1.0.25
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew O'Riordan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara
|
@@ -240,7 +240,11 @@ files:
|
|
240
240
|
homepage: http://github.com/mattheworiordan/capybara-screenshot
|
241
241
|
licenses:
|
242
242
|
- MIT
|
243
|
-
metadata:
|
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.25
|
247
|
+
source_code_uri: https://github.com/mattheworiordan/capybara-screenshot/tree/v1.0.25
|
244
248
|
post_install_message:
|
245
249
|
rdoc_options: []
|
246
250
|
require_paths:
|
@@ -256,8 +260,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
256
260
|
- !ruby/object:Gem::Version
|
257
261
|
version: '0'
|
258
262
|
requirements: []
|
259
|
-
|
260
|
-
rubygems_version: 2.4.8
|
263
|
+
rubygems_version: 3.0.3
|
261
264
|
signing_key:
|
262
265
|
specification_version: 4
|
263
266
|
summary: Automatically create snapshots when Cucumber steps fail with Capybara and
|