capybara-screenshot 1.0.26 → 1.0.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b73d3b8338a3c2f426d7835f4396565c0bfe28b939f610337c331099f93f52b5
4
- data.tar.gz: c5ec9f343c703e5ac2700b84dcde63a094c3609787ea7b1cfbbd1f470a5b0ce4
3
+ metadata.gz: 3622fc9e4c9348592f801aa4ded346ed13186a2a064d1cc93f004ab0a34a752d
4
+ data.tar.gz: 2388d305280af10e3ef3b6a13fd8b08e450f2922a1a35d6e8f32a50933ae82d1
5
5
  SHA512:
6
- metadata.gz: 4cd11454a82290ef985a5341e0dad1eaea6296ca5b6ea1f17522a5f8f43b6c68dd71cfd17426c8204fd352488b6ea876d2e8493b2ec0ce2e575590e13302b456
7
- data.tar.gz: d17d96491ebc960f4fa47eec58b9dd60610c4a7839e878d8d40c3003cb054e891fc38e958ba42dbcf7ded095385fbb725cdd9e33e368fec51cd89358653c3576
6
+ metadata.gz: eff915aea70bac7983ee64a7cae410181c11bcca379f2e11e48219a2fbf5811a1724aa761e9da6d5218f6700d1b687a91c29763c866c3f999d8d8a2cf9ba490a
7
+ data.tar.gz: 1cc29529123428346d2f0e85f26cf65d2140ab2fc2ae80f08548f32de97dea044fec9c4635b41d187774e56c08c44476aea3c509cf62f0a307d556b5d9389582
@@ -0,0 +1,35 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: rspec
9
+
10
+ on:
11
+ push:
12
+ branches: ["master"]
13
+ pull_request:
14
+ branches: ["master"]
15
+
16
+ permissions:
17
+ contents: read
18
+
19
+ jobs:
20
+ test:
21
+ runs-on: ubuntu-latest
22
+ strategy:
23
+ matrix:
24
+ ruby-version: ["2.6", "2.7", "3.0"]
25
+
26
+ steps:
27
+ - uses: actions/checkout@v4
28
+ - name: Set up Ruby
29
+ uses: ruby/setup-ruby@v1
30
+ # uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0
31
+ with:
32
+ ruby-version: ${{ matrix.ruby-version }}
33
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
34
+ - name: Run tests
35
+ run: bundle exec rspec
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ 25 Feb 2025 - 1.0.26 -> 1.0.27
2
+
3
+ * [Add ability to manually save screenshots with custom prefixes](https://github.com/mattheworiordan/capybara-screenshot/pull/302)
4
+ * [Support headless Firefox screenshots](https://github.com/mattheworiordan/capybara-screenshot/pull/300)
5
+ * [Add support for Playwright driver](https://github.com/mattheworiordan/capybara-screenshot/commit/23a27be5392c7dbc706651d7adc124d8e7c920a0)
6
+ * [Add a workflow for CI on GitHub Actions](https://github.com/mattheworiordan/capybara-screenshot/pull/301)
7
+
1
8
  21 Dec 2021 - 1.0.25 -> 1.0.26
2
9
 
3
10
  * [Take screenshots of current window (when using multiple windows)](https://github.com/mattheworiordan/capybara-screenshot/pull/287)
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', '~> 13.0'
7
+ gem 'rake', '~> 10.0'
8
8
  gem 'appraisal', '~> 2.0'
9
9
  gem 'aruba', '~> 0.14.0'
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  capybara-screenshot gem
2
2
  =======================
3
3
 
4
- [![Build Status](https://travis-ci.org/mattheworiordan/capybara-screenshot.svg)](https://travis-ci.org/mattheworiordan/capybara-screenshot)
4
+ [![Build Status](https://github.com/mattheworiordan/capybara-screenshot/actions/workflows/ci.yml/badge.svg)](https://github.com/mattheworiordan/capybara-screenshot/actions/workflows/ci.yml)
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
 
@@ -100,12 +100,21 @@ Anywhere the Capybara DSL methods (visit, click etc.) are available so too are t
100
100
 
101
101
  ```ruby
102
102
  screenshot_and_save_page
103
+
104
+ # with custom prefix
105
+ screenshot_and_save_page(filename_prefix: 'custom_prefix')
106
+
107
+ # image only, with custom prefix:
108
+ screenshot_and_save_page(filename_prefix: 'custom_prefix', save_html: false)
103
109
  ```
104
110
 
105
111
  Or for screenshot only, which will automatically open the image:
106
112
 
107
113
  ```ruby
108
114
  screenshot_and_open_image
115
+
116
+ # with custom prefix
117
+ screenshot_and_open_image(filename_prefix: 'custom_prefix')
109
118
  ```
110
119
 
111
120
  These are just calls on the main library methods:
@@ -319,7 +328,7 @@ Please raise an issue at [https://github.com/mattheworiordan/capybara-screenshot
319
328
 
320
329
  #### Contributions
321
330
 
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.
331
+ 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 "rspec"` locally to test your changes against all versions of testing framework gems supported.
323
332
 
324
333
  #### Rubygems
325
334
 
data/Rakefile CHANGED
@@ -1,40 +1,6 @@
1
- require 'rubygems'
2
- require 'bundler/setup'
1
+ require "rubygems"
2
+ require "bundler/setup"
3
3
 
4
4
  Bundler::GemHelper.install_tasks
5
5
 
6
- require 'rspec/core/rake_task'
7
-
8
- rspec_rake_task = RSpec::Core::RakeTask.new(:spec)
9
-
10
- task default: [:spec]
11
-
12
- def target_gem
13
- gem_file = ENV['BUNDLE_GEMFILE'] || ''
14
- targets = %w(cucumber spinach rspec)
15
-
16
- target = gem_file.match(/(#{targets.join('|')})/)
17
- if target && targets.include?(target[1])
18
- target[1].to_sym
19
- else
20
- []
21
- end
22
- end
23
-
24
- namespace :travis do
25
- task :ci => target_gem do
26
- Rake::Task['spec'].invoke
27
- end
28
-
29
- task :cucumber do
30
- rspec_rake_task.pattern = 'spec/cucumber'
31
- end
32
-
33
- task :spinach do
34
- rspec_rake_task.pattern = 'spec/spinach'
35
- end
36
-
37
- task :rspec do
38
- rspec_rake_task.pattern = 'spec/rspec'
39
- end
40
- end
6
+ require "rspec/core/rake_task"
@@ -19,12 +19,12 @@ module Capybara
19
19
  # Adds class methods to Capybara module and gets mixed into
20
20
  # the current scope during Cucumber and RSpec tests
21
21
 
22
- def screenshot_and_save_page
23
- Capybara::Screenshot.screenshot_and_save_page
22
+ def screenshot_and_save_page(filename_prefix: nil, save_html: true)
23
+ Capybara::Screenshot.screenshot_and_save_page(filename_prefix: filename_prefix, save_html: save_html)
24
24
  end
25
25
 
26
- def screenshot_and_open_image
27
- Capybara::Screenshot.screenshot_and_open_image
26
+ def screenshot_and_open_image(filename_prefix: nil)
27
+ Capybara::Screenshot.screenshot_and_open_image(filename_prefix: filename_prefix)
28
28
  end
29
29
  end
30
30
 
@@ -1,5 +1,5 @@
1
1
  module Capybara
2
2
  module Screenshot
3
- VERSION = '1.0.26'
3
+ VERSION = '1.0.27'
4
4
  end
5
5
  end
@@ -29,17 +29,19 @@ module Capybara
29
29
  RSpec.add_link_to_screenshot_for_failed_examples = value
30
30
  end
31
31
 
32
- def self.screenshot_and_save_page
33
- saver = new_saver(Capybara, Capybara.page)
32
+ def self.screenshot_and_save_page(filename_prefix: nil, save_html: true)
33
+ saver = new_saver(Capybara, Capybara.page, save_html, filename_prefix)
34
34
  if saver.save
35
35
  {:html => saver.html_path, :image => saver.screenshot_path}
36
+ elsif !save_html
37
+ warn 'WARN: no screenshot has been saved. You should configure the driver used by Capybara to save images.'
36
38
  end
37
39
  end
38
40
 
39
- def self.screenshot_and_open_image
41
+ def self.screenshot_and_open_image(filename_prefix: nil)
40
42
  require "launchy"
41
43
 
42
- saver = new_saver(Capybara, Capybara.page, false)
44
+ saver = new_saver(Capybara, Capybara.page, false, filename_prefix)
43
45
  if saver.save
44
46
  Launchy.open saver.screenshot_path
45
47
  {:html => nil, :image => saver.screenshot_path}
@@ -161,6 +163,7 @@ Capybara::Screenshot.class_eval do
161
163
  end
162
164
 
163
165
  register_driver :selenium, &selenium_block
166
+ register_driver :selenium_headless, &selenium_block
164
167
  register_driver :selenium_chrome, &selenium_block
165
168
  register_driver :selenium_chrome_headless, &selenium_block
166
169
 
@@ -198,6 +201,12 @@ Capybara::Screenshot.class_eval do
198
201
  register_driver(:cuprite) do |driver, path|
199
202
  driver.render(path, :full => true)
200
203
  end
204
+
205
+ register_driver(:playwright) do |driver, path|
206
+ driver.with_playwright_page do |page|
207
+ page.screenshot(path: path, fullPage: true)
208
+ end
209
+ end
201
210
  end
202
211
 
203
212
  # Register filename prefix formatters
@@ -61,6 +61,26 @@ describe "Using Capybara::Screenshot with Cucumber" do
61
61
  expect('tmp/my_screenshot.html').to have_file_content('This is a different page')
62
62
  end
63
63
 
64
+ it 'saves a screenshot with custom prefix' do
65
+ run_case(<<-CUCUMBER)
66
+ Feature: Custom prefix
67
+ Scenario: Screenshot with custom prefix
68
+ Given I visit "/"
69
+ And I save the page with a custom prefix
70
+ CUCUMBER
71
+ expect('tmp/custom_prefix.html').to have_file_content('This is the root page')
72
+ end
73
+
74
+ it 'displays a warning when a screenshot without HTML is asked but not saved' do
75
+ run_case(<<-CUCUMBER)
76
+ Feature: Custom prefix
77
+ Scenario: Empty screenshot
78
+ Given I visit "/different_page"
79
+ And I take a screenshot which is not saved
80
+ CUCUMBER
81
+ expect(last_command_started.output).to include('WARN: no screenshot has been saved.')
82
+ end
83
+
64
84
  context 'pruning' do
65
85
  before do
66
86
  create_screenshot_for_pruning
@@ -16,3 +16,11 @@ end
16
16
  Then(/^I trigger an unhandled exception/) do
17
17
  raise "you can't handle me"
18
18
  end
19
+
20
+ Then(/^I save the page with a custom prefix$/) do
21
+ screenshot_and_save_page filename_prefix: 'custom_prefix'
22
+ end
23
+
24
+ Then(/^I take a screenshot which is not saved$/) do
25
+ screenshot_and_save_page save_html: false
26
+ end
@@ -28,7 +28,7 @@ describe "Using Capybara::Screenshot with MiniTest" do
28
28
 
29
29
  it 'saves a screenshot on failure' do
30
30
  run_failing_case <<-RUBY
31
- class TestFailure < MiniTest::Unit::TestCase
31
+ class TestFailure < Minitest::Test
32
32
  include Capybara::DSL
33
33
 
34
34
  def test_failure
@@ -43,7 +43,7 @@ describe "Using Capybara::Screenshot with MiniTest" do
43
43
 
44
44
  it 'saves a screenshot for the correct session for failures using_session' do
45
45
  run_failing_case <<-RUBY
46
- class TestFailure < Minitest::Unit::TestCase
46
+ class TestFailure < Minitest::Test
47
47
  include Capybara::DSL
48
48
 
49
49
  def test_failure
@@ -64,7 +64,7 @@ describe "Using Capybara::Screenshot with MiniTest" do
64
64
  create_screenshot_for_pruning
65
65
  configure_prune_strategy :last_run
66
66
  run_failing_case <<-RUBY
67
- class TestFailure < Minitest::Unit::TestCase
67
+ class TestFailure < Minitest::Test
68
68
  include Capybara::DSL
69
69
 
70
70
  def test_failure
@@ -135,9 +135,11 @@ describe Capybara::Screenshot::S3Saver do
135
135
  expect(File).to receive(:open).with(html_path).and_yield(html_file)
136
136
 
137
137
  expect(s3_client).to receive(:put_object).with(
138
- bucket: bucket_name,
139
- key: 'bar.html',
140
- body: html_file
138
+ {
139
+ bucket: bucket_name,
140
+ key: "bar.html",
141
+ body: html_file
142
+ }
141
143
  )
142
144
 
143
145
  expect(s3_saver).to receive(:determine_bucket_host).and_call_original
@@ -155,9 +157,11 @@ describe Capybara::Screenshot::S3Saver do
155
157
  expect(File).to receive(:open).with(screenshot_path).and_yield(screenshot_file)
156
158
 
157
159
  expect(s3_client).to receive(:put_object).with(
158
- bucket: bucket_name,
159
- key: 'bim.jpg',
160
- body: screenshot_file
160
+ {
161
+ bucket: bucket_name,
162
+ key: "bim.jpg",
163
+ body: screenshot_file
164
+ }
161
165
  )
162
166
 
163
167
  s3_saver.save
@@ -177,10 +181,12 @@ describe Capybara::Screenshot::S3Saver do
177
181
  expect(File).to receive(:open).with(html_path).and_yield(html_file)
178
182
 
179
183
  expect(s3_client).to receive(:put_object).with(
180
- bucket: bucket_name,
181
- key: 'bar.html',
182
- body: html_file,
183
- acl: 'public-read'
184
+ {
185
+ bucket: bucket_name,
186
+ key: "bar.html",
187
+ body: html_file,
188
+ acl: "public-read"
189
+ }
184
190
  )
185
191
 
186
192
  s3_saver.save
@@ -196,10 +202,12 @@ describe Capybara::Screenshot::S3Saver do
196
202
  expect(File).to receive(:open).with(screenshot_path).and_yield(screenshot_file)
197
203
 
198
204
  expect(s3_client).to receive(:put_object).with(
199
- bucket: bucket_name,
200
- key: 'bim.jpg',
201
- body: screenshot_file,
202
- acl: 'public-read'
205
+ {
206
+ bucket: bucket_name,
207
+ key: "bim.jpg",
208
+ body: screenshot_file,
209
+ acl: "public-read"
210
+ }
203
211
  )
204
212
 
205
213
  s3_saver.save
@@ -217,9 +225,11 @@ describe Capybara::Screenshot::S3Saver do
217
225
  expect(File).to receive(:open).with(html_path).and_yield(html_file)
218
226
 
219
227
  expect(s3_client).to receive(:put_object).with(
220
- bucket: bucket_name,
221
- key: 'some/path/bar.html',
222
- body: html_file
228
+ {
229
+ bucket: bucket_name,
230
+ key: "some/path/bar.html",
231
+ body: html_file
232
+ }
223
233
  )
224
234
 
225
235
  s3_saver_with_key_prefix.save
@@ -235,9 +245,11 @@ describe Capybara::Screenshot::S3Saver do
235
245
  expect(File).to receive(:open).with(screenshot_path).and_yield(screenshot_file)
236
246
 
237
247
  expect(s3_client).to receive(:put_object).with(
238
- bucket: bucket_name,
239
- key: 'some/path/bim.jpg',
240
- body: screenshot_file
248
+ {
249
+ bucket: bucket_name,
250
+ key: "some/path/bim.jpg",
251
+ body: screenshot_file
252
+ }
241
253
  )
242
254
 
243
255
  s3_saver_with_key_prefix.save
@@ -256,10 +268,12 @@ describe Capybara::Screenshot::S3Saver do
256
268
  expect(File).to receive(:open).with(html_path).and_yield(html_file)
257
269
 
258
270
  expect(s3_client).to receive(:put_object).with(
259
- bucket: bucket_name,
260
- key: 'some/path/bar.html',
261
- body: html_file,
262
- acl: 'public-read'
271
+ {
272
+ bucket: bucket_name,
273
+ key: "some/path/bar.html",
274
+ body: html_file,
275
+ acl: "public-read"
276
+ }
263
277
  )
264
278
 
265
279
  s3_saver_with_key_prefix.save
@@ -275,10 +289,12 @@ describe Capybara::Screenshot::S3Saver do
275
289
  expect(File).to receive(:open).with(screenshot_path).and_yield(screenshot_file)
276
290
 
277
291
  expect(s3_client).to receive(:put_object).with(
278
- bucket: bucket_name,
279
- key: 'some/path/bim.jpg',
280
- body: screenshot_file,
281
- acl: 'public-read'
292
+ {
293
+ bucket: bucket_name,
294
+ key: "some/path/bim.jpg",
295
+ body: screenshot_file,
296
+ acl: "public-read"
297
+ }
282
298
  )
283
299
 
284
300
  s3_saver_with_key_prefix.save
@@ -311,6 +311,24 @@ describe Capybara::Screenshot::Saver do
311
311
  end
312
312
  end
313
313
 
314
+ describe "with playwright driver" do
315
+ let(:playwright_page_mock) {
316
+ double('Playwright Page Mock').as_null_object
317
+ }
318
+
319
+ before do
320
+ allow(capybara_mock).to receive(:current_driver).and_return(:playwright)
321
+ end
322
+
323
+ it 'saves driver screenshot via playwright page with :fullPage => true' do
324
+ expect(driver_mock).to receive(:with_playwright_page).and_yield(playwright_page_mock)
325
+ expect(playwright_page_mock).to receive(:screenshot).with(path: screenshot_path, fullPage: true)
326
+
327
+ saver.save
328
+ expect(saver).to be_screenshot_saved
329
+ end
330
+ end
331
+
314
332
  describe "with webkit driver" do
315
333
  before do
316
334
  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.26
4
+ version: 1.0.27
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: 2022-01-12 00:00:00.000000000 Z
11
+ date: 2026-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara
@@ -178,9 +178,9 @@ executables: []
178
178
  extensions: []
179
179
  extra_rdoc_files: []
180
180
  files:
181
+ - ".github/workflows/ci.yml"
181
182
  - ".gitignore"
182
183
  - ".rspec"
183
- - ".travis.yml"
184
184
  - Appraisals
185
185
  - CHANGELOG.md
186
186
  - Gemfile
@@ -243,8 +243,8 @@ licenses:
243
243
  metadata:
244
244
  bug_tracker_uri: https://github.com/mattheworiordan/capybara-screenshot/issues
245
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
246
+ documentation_uri: https://www.rubydoc.info/gems/capybara-screenshot/1.0.27
247
+ source_code_uri: https://github.com/mattheworiordan/capybara-screenshot/tree/v1.0.27
248
248
  post_install_message:
249
249
  rdoc_options: []
250
250
  require_paths:
@@ -260,7 +260,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
260
260
  - !ruby/object:Gem::Version
261
261
  version: '0'
262
262
  requirements: []
263
- rubygems_version: 3.0.3
263
+ rubygems_version: 3.5.9
264
264
  signing_key:
265
265
  specification_version: 4
266
266
  summary: Automatically create snapshots when Cucumber steps fail with Capybara and
data/.travis.yml DELETED
@@ -1,17 +0,0 @@
1
- language: ruby
2
- script: "bundle exec rake travis:ci"
3
- rvm:
4
- - 2.0.0
5
- - 2.1.10
6
- - 2.2.10
7
- - 2.3.8
8
- - 2.4.9
9
- - 2.5.7
10
- - 2.6.5
11
- gemfile:
12
- - gemfiles/cucumber.1.3.gemfile
13
- - gemfiles/cucumber.2.4.gemfile
14
- - gemfiles/latest.gemfile
15
- - gemfiles/rspec.3.0.gemfile
16
- - gemfiles/rspec.3.3.gemfile
17
- - gemfiles/spinach.0.8.gemfile