capybara-screenshot 1.0.13 → 1.0.26
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +11 -12
- data/Appraisals +14 -16
- data/CHANGELOG.md +69 -0
- data/Gemfile +4 -3
- data/README.md +96 -30
- data/capybara-screenshot.gemspec +12 -5
- data/gemfiles/cucumber.1.3.gemfile +12 -0
- data/gemfiles/cucumber.2.4.gemfile +12 -0
- data/gemfiles/latest.gemfile +5 -2
- data/gemfiles/rspec.3.0.gemfile +5 -2
- data/gemfiles/rspec.3.3.gemfile +12 -0
- data/gemfiles/spinach.0.8.gemfile +12 -0
- data/lib/capybara-screenshot/callbacks.rb +44 -0
- data/lib/capybara-screenshot/capybara.rb +26 -10
- data/lib/capybara-screenshot/cucumber.rb +12 -5
- data/lib/capybara-screenshot/minitest.rb +1 -1
- data/lib/capybara-screenshot/pruner.rb +5 -1
- 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/html_link_reporter.rb +1 -1
- data/lib/capybara-screenshot/rspec/text_reporter.rb +2 -2
- data/lib/capybara-screenshot/rspec.rb +25 -3
- data/lib/capybara-screenshot/s3_saver.rb +39 -11
- data/lib/capybara-screenshot/saver.rb +60 -15
- data/lib/capybara-screenshot/version.rb +1 -1
- data/lib/capybara-screenshot.rb +38 -3
- data/spec/cucumber/cucumber_spec.rb +4 -8
- data/spec/feature/minitest_spec.rb +2 -6
- data/spec/feature/testunit_spec.rb +3 -7
- data/spec/rspec/rspec_spec.rb +36 -8
- data/spec/spinach/spinach_spec.rb +4 -8
- data/spec/support/aruba.rb +0 -1
- data/spec/support/common_setup.rb +13 -5
- data/spec/unit/capybara-screenshot_spec.rb +2 -1
- data/spec/unit/capybara_spec.rb +13 -0
- data/spec/unit/pruner_spec.rb +2 -2
- 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 +196 -14
- data/spec/unit/saver_spec.rb +132 -16
- metadata +19 -17
- data/gemfiles/cucumber.1.2.gemfile +0 -9
- data/gemfiles/cucumber.1.3.0.gemfile +0 -9
- data/gemfiles/rspec.2.14.gemfile +0 -9
- data/gemfiles/rspec.2.99.gemfile +0 -9
- data/gemfiles/spinach.0.7.gemfile +0 -9
- data/gemfiles/spinach.0.8.0.gemfile +0 -9
@@ -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
|
-
|
23
|
-
|
24
|
-
|
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
|
@@ -13,6 +13,7 @@ module Capybara
|
|
13
13
|
lambda { prune_with_last_run_strategy }
|
14
14
|
when Hash
|
15
15
|
raise ArgumentError, ":keep key is required" unless strategy[:keep]
|
16
|
+
raise ArgumentError, ":keep must be a Integer" unless strategy[:keep].kind_of?(Integer)
|
16
17
|
raise ArgumentError, ":keep value must be number greater than zero" unless strategy[:keep].to_i > 0
|
17
18
|
lambda { prune_with_numeric_strategy(strategy[:keep].to_i) }
|
18
19
|
else
|
@@ -25,7 +26,10 @@ module Capybara
|
|
25
26
|
end
|
26
27
|
|
27
28
|
private
|
28
|
-
|
29
|
+
|
30
|
+
def strategy_proc
|
31
|
+
@strategy_proc
|
32
|
+
end
|
29
33
|
|
30
34
|
def wildcard_path
|
31
35
|
File.expand_path('*.{html,png}', Screenshot.capybara_root)
|
@@ -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
|
@@ -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>"
|
@@ -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
|
@@ -43,7 +43,8 @@ module Capybara
|
|
43
43
|
"RSpec::Core::Formatters::JsonFormatter" => Capybara::Screenshot::RSpec::JsonReporter,
|
44
44
|
"RSpec::Core::Formatters::TextMateFormatter" => Capybara::Screenshot::RSpec::TextMateLinkReporter, # RSpec 2
|
45
45
|
"RSpec::Mate::Formatters::TextMateFormatter" => Capybara::Screenshot::RSpec::TextMateLinkReporter, # RSpec 3
|
46
|
-
"Fuubar" => Capybara::Screenshot::RSpec::TextReporter
|
46
|
+
"Fuubar" => Capybara::Screenshot::RSpec::TextReporter,
|
47
|
+
"Spec::Runner::Formatter::TeamcityFormatter" => Capybara::Screenshot::RSpec::TextReporter
|
47
48
|
}
|
48
49
|
|
49
50
|
class << self
|
@@ -52,7 +53,7 @@ module Capybara
|
|
52
53
|
def after_failed_example(example)
|
53
54
|
if example.example_group.include?(Capybara::DSL) # Capybara DSL method has been included for a feature we can snapshot
|
54
55
|
Capybara.using_session(Capybara::Screenshot.final_session_name) do
|
55
|
-
if Capybara.
|
56
|
+
if Capybara::Screenshot.autosave_on_failure && failed?(example) && Capybara.page.current_url != ''
|
56
57
|
filename_prefix = Capybara::Screenshot.filename_prefix_for(:rspec, example)
|
57
58
|
|
58
59
|
saver = Capybara::Screenshot.new_saver(Capybara, Capybara.page, true, filename_prefix)
|
@@ -65,6 +66,18 @@ module Capybara
|
|
65
66
|
end
|
66
67
|
end
|
67
68
|
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def failed?(example)
|
73
|
+
return true if example.exception
|
74
|
+
return false unless defined?(::RSpec::Expectations::FailureAggregator)
|
75
|
+
|
76
|
+
failure_notifier = ::RSpec::Support.failure_notifier
|
77
|
+
return false unless failure_notifier.is_a?(::RSpec::Expectations::FailureAggregator)
|
78
|
+
|
79
|
+
failure_notifier.failures.any? || failure_notifier.other_errors.any?
|
80
|
+
end
|
68
81
|
end
|
69
82
|
|
70
83
|
self.add_link_to_screenshot_for_failed_examples = true
|
@@ -77,7 +90,15 @@ RSpec.configure do |config|
|
|
77
90
|
Capybara::Screenshot.final_session_name = nil
|
78
91
|
end
|
79
92
|
|
80
|
-
|
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
|
101
|
+
config.after(type: :feature) do |example_from_block_arg|
|
81
102
|
# RSpec 3 no longer defines `example`, but passes the example as block argument instead
|
82
103
|
example = config.respond_to?(:expose_current_running_example_as) ? example_from_block_arg : self.example
|
83
104
|
|
@@ -88,6 +109,7 @@ RSpec.configure do |config|
|
|
88
109
|
if Capybara::Screenshot::RSpec.add_link_to_screenshot_for_failed_examples
|
89
110
|
RSpec.configuration.formatters.each do |formatter|
|
90
111
|
next unless (reporter_module = Capybara::Screenshot::RSpec::REPORTERS[formatter.class.to_s])
|
112
|
+
next if formatter.singleton_class.included_modules.include?(reporter_module)
|
91
113
|
formatter.singleton_class.send :include, reporter_module
|
92
114
|
end
|
93
115
|
end
|
@@ -1,17 +1,22 @@
|
|
1
|
-
require 'aws-sdk'
|
1
|
+
require 'aws-sdk-s3'
|
2
2
|
|
3
3
|
module Capybara
|
4
4
|
module Screenshot
|
5
5
|
class S3Saver
|
6
6
|
DEFAULT_REGION = 'us-east-1'
|
7
7
|
|
8
|
-
|
8
|
+
attr_accessor :html_path, :screenshot_path
|
9
|
+
|
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]
|
15
|
+
@key_prefix = options[:key_prefix]
|
16
|
+
@object_configuration = object_configuration
|
12
17
|
end
|
13
18
|
|
14
|
-
def self.new_with_configuration(saver, configuration)
|
19
|
+
def self.new_with_configuration(saver, configuration, object_configuration)
|
15
20
|
default_s3_client_credentials = {
|
16
21
|
region: DEFAULT_REGION
|
17
22
|
}
|
@@ -23,19 +28,31 @@ module Capybara
|
|
23
28
|
s3_client = Aws::S3::Client.new(s3_client_credentials)
|
24
29
|
bucket_name = configuration.fetch(:bucket_name)
|
25
30
|
|
26
|
-
new(saver, s3_client, bucket_name)
|
31
|
+
new(saver, s3_client, bucket_name, object_configuration, configuration)
|
27
32
|
rescue KeyError
|
28
33
|
raise "Invalid S3 Configuration #{configuration}. Please refer to the documentation for the necessary configurations."
|
29
34
|
end
|
30
35
|
|
31
36
|
def save_and_upload_screenshot
|
32
|
-
save_and do |local_file_path|
|
37
|
+
save_and do |type, local_file_path|
|
33
38
|
File.open(local_file_path) do |file|
|
39
|
+
s3_upload_path = "#{@key_prefix}#{File.basename(local_file_path)}"
|
40
|
+
|
41
|
+
object_payload = {
|
42
|
+
bucket: bucket_name,
|
43
|
+
key: s3_upload_path,
|
44
|
+
body: file
|
45
|
+
}
|
46
|
+
|
47
|
+
object_payload.merge!(object_configuration) unless object_configuration.empty?
|
48
|
+
|
34
49
|
s3_client.put_object(
|
35
|
-
|
36
|
-
key: File.basename(local_file_path),
|
37
|
-
body: file
|
50
|
+
object_payload
|
38
51
|
)
|
52
|
+
|
53
|
+
host = bucket_host || determine_bucket_host
|
54
|
+
|
55
|
+
send("#{type}_path=", "https://#{host}/#{s3_upload_path}")
|
39
56
|
end
|
40
57
|
end
|
41
58
|
end
|
@@ -51,13 +68,24 @@ module Capybara
|
|
51
68
|
private
|
52
69
|
attr_reader :saver,
|
53
70
|
:s3_client,
|
54
|
-
:bucket_name
|
71
|
+
:bucket_name,
|
72
|
+
:bucket_host,
|
73
|
+
:object_configuration
|
74
|
+
:key_prefix
|
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
|
55
83
|
|
56
84
|
def save_and
|
57
85
|
saver.save
|
58
86
|
|
59
|
-
yield(saver.html_path) if block_given? && saver.html_saved?
|
60
|
-
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?
|
61
89
|
end
|
62
90
|
end
|
63
91
|
end
|
@@ -1,9 +1,16 @@
|
|
1
1
|
require 'capybara-screenshot/helpers'
|
2
|
+
require 'capybara-screenshot/callbacks'
|
2
3
|
|
3
4
|
module Capybara
|
4
5
|
module Screenshot
|
5
6
|
class Saver
|
7
|
+
include Capybara::Screenshot::Callbacks
|
8
|
+
|
9
|
+
define_callback :after_save_html
|
10
|
+
define_callback :after_save_screenshot
|
11
|
+
|
6
12
|
attr_reader :capybara, :page, :file_base_name
|
13
|
+
|
7
14
|
def initialize(capybara, page, html_save=true, filename_prefix='screenshot')
|
8
15
|
@capybara, @page, @html_save = capybara, page, html_save
|
9
16
|
time_now = Time.now
|
@@ -19,34 +26,50 @@ module Capybara
|
|
19
26
|
end
|
20
27
|
|
21
28
|
def save
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
29
|
+
current_path do |path|
|
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
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
27
48
|
end
|
28
49
|
|
29
50
|
def save_html
|
30
51
|
path = html_path
|
31
|
-
|
52
|
+
clear_save_path do
|
32
53
|
if Capybara::VERSION.match(/^\d+/)[0] == '1'
|
33
|
-
capybara.save_page(page.body,
|
54
|
+
capybara.save_page(page.body, path.to_s)
|
34
55
|
else
|
35
|
-
capybara.save_page(
|
56
|
+
capybara.save_page(path.to_s)
|
36
57
|
end
|
37
58
|
end
|
38
59
|
@html_saved = true
|
60
|
+
run_callbacks :after_save_html, html_path if html_saved?
|
39
61
|
end
|
40
62
|
|
41
63
|
def save_screenshot
|
42
64
|
path = screenshot_path
|
43
|
-
|
65
|
+
clear_save_path do
|
44
66
|
result = Capybara::Screenshot.registered_drivers.fetch(capybara.current_driver) { |driver_name|
|
45
67
|
warn "capybara-screenshot could not detect a screenshot driver for '#{capybara.current_driver}'. Saving with default with unknown results."
|
46
68
|
Capybara::Screenshot.registered_drivers[:default]
|
47
69
|
}.call(page.driver, path)
|
48
70
|
@screenshot_saved = result != :not_supported
|
49
71
|
end
|
72
|
+
run_callbacks :after_save_screenshot, screenshot_path if screenshot_saved?
|
50
73
|
end
|
51
74
|
|
52
75
|
def html_path
|
@@ -65,15 +88,15 @@ module Capybara
|
|
65
88
|
@screenshot_saved
|
66
89
|
end
|
67
90
|
|
68
|
-
# If Capybara.
|
91
|
+
# If Capybara::Screenshot.capybara_tmp_path is set then
|
69
92
|
# the html_path or screenshot_path can be appended to this path in
|
70
93
|
# some versions of Capybara instead of using it as an absolute path
|
71
|
-
def
|
72
|
-
old_path = Capybara.
|
73
|
-
Capybara.
|
94
|
+
def clear_save_path
|
95
|
+
old_path = Capybara::Screenshot.capybara_tmp_path
|
96
|
+
Capybara::Screenshot.capybara_tmp_path = nil
|
74
97
|
yield
|
75
98
|
ensure
|
76
|
-
Capybara.
|
99
|
+
Capybara::Screenshot.capybara_tmp_path = old_path
|
77
100
|
end
|
78
101
|
|
79
102
|
def output_screenshot_path
|
@@ -88,6 +111,16 @@ module Capybara
|
|
88
111
|
|
89
112
|
private
|
90
113
|
|
114
|
+
def current_path
|
115
|
+
# the current_path may raise error in selenium
|
116
|
+
begin
|
117
|
+
path = page.current_path.to_s
|
118
|
+
rescue StandardError => e
|
119
|
+
warn "WARN: Screenshot could not be saved. `page.current_path` raised exception: #{e.inspect}."
|
120
|
+
end
|
121
|
+
yield path if path
|
122
|
+
end
|
123
|
+
|
91
124
|
def output(message)
|
92
125
|
puts " #{CapybaraScreenshot::Helpers.yellow(message)}"
|
93
126
|
end
|
@@ -101,13 +134,25 @@ module Capybara
|
|
101
134
|
# which('ruby') #=> /usr/bin/ruby
|
102
135
|
def which(cmd)
|
103
136
|
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
137
|
+
|
104
138
|
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
105
139
|
exts.each { |ext|
|
106
140
|
exe = File.join(path, "#{cmd}#{ext}")
|
107
141
|
return exe if File.executable?(exe) && !File.directory?(exe)
|
108
142
|
}
|
109
143
|
end
|
110
|
-
|
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
|
111
156
|
end
|
112
157
|
end
|
113
158
|
end
|
data/lib/capybara-screenshot.rb
CHANGED
@@ -10,6 +10,7 @@ module Capybara
|
|
10
10
|
attr_writer :final_session_name
|
11
11
|
attr_accessor :prune_strategy
|
12
12
|
attr_accessor :s3_configuration
|
13
|
+
attr_accessor :s3_object_configuration
|
13
14
|
end
|
14
15
|
|
15
16
|
self.autosave_on_failure = true
|
@@ -20,6 +21,7 @@ module Capybara
|
|
20
21
|
self.webkit_options = {}
|
21
22
|
self.prune_strategy = :keep_all
|
22
23
|
self.s3_configuration = {}
|
24
|
+
self.s3_object_configuration = {}
|
23
25
|
|
24
26
|
def self.append_screenshot_path=(value)
|
25
27
|
$stderr.puts "WARNING: Capybara::Screenshot.append_screenshot_path is deprecated. " +
|
@@ -56,7 +58,7 @@ module Capybara
|
|
56
58
|
end
|
57
59
|
|
58
60
|
def self.capybara_root
|
59
|
-
@capybara_root ||= if defined?(::Rails) && ::Rails.root.present?
|
61
|
+
@capybara_root ||= if defined?(::Rails) && ::Rails.respond_to?(:root) && ::Rails.root.present?
|
60
62
|
::Rails.root.join capybara_tmp_path
|
61
63
|
elsif defined?(Padrino)
|
62
64
|
File.expand_path(capybara_tmp_path, Padrino.root)
|
@@ -97,12 +99,20 @@ module Capybara
|
|
97
99
|
|
98
100
|
unless s3_configuration.empty?
|
99
101
|
require 'capybara-screenshot/s3_saver'
|
100
|
-
saver = S3Saver.new_with_configuration(saver, s3_configuration)
|
102
|
+
saver = S3Saver.new_with_configuration(saver, s3_configuration, s3_object_configuration)
|
101
103
|
end
|
102
104
|
|
103
105
|
return saver
|
104
106
|
end
|
105
107
|
|
108
|
+
def self.after_save_html &block
|
109
|
+
Saver.after_save_html(&block)
|
110
|
+
end
|
111
|
+
|
112
|
+
def self.after_save_screenshot &block
|
113
|
+
Saver.after_save_screenshot(&block)
|
114
|
+
end
|
115
|
+
|
106
116
|
private
|
107
117
|
|
108
118
|
# If the path isn't set, default to the current directory
|
@@ -115,6 +125,19 @@ module Capybara
|
|
115
125
|
Capybara.save_and_open_page_path
|
116
126
|
end || '.'
|
117
127
|
end
|
128
|
+
|
129
|
+
# Configure the path unless '.'
|
130
|
+
def self.capybara_tmp_path=(path)
|
131
|
+
return if path == '.'
|
132
|
+
|
133
|
+
# `#save_and_open_page_path` is deprecated
|
134
|
+
# https://github.com/jnicklas/capybara/blob/48ab1ede946dec2250a2d1d8cbb3313f25096456/History.md#L37
|
135
|
+
if Capybara.respond_to?(:save_path)
|
136
|
+
Capybara.save_path = path
|
137
|
+
else
|
138
|
+
Capybara.save_and_open_page_path = path
|
139
|
+
end
|
140
|
+
end
|
118
141
|
end
|
119
142
|
end
|
120
143
|
|
@@ -133,10 +156,14 @@ Capybara::Screenshot.class_eval do
|
|
133
156
|
:not_supported
|
134
157
|
end
|
135
158
|
|
136
|
-
|
159
|
+
selenium_block = proc do |driver, path|
|
137
160
|
driver.browser.save_screenshot(path)
|
138
161
|
end
|
139
162
|
|
163
|
+
register_driver :selenium, &selenium_block
|
164
|
+
register_driver :selenium_chrome, &selenium_block
|
165
|
+
register_driver :selenium_chrome_headless, &selenium_block
|
166
|
+
|
140
167
|
register_driver(:poltergeist) do |driver, path|
|
141
168
|
driver.render(path, :full => true)
|
142
169
|
end
|
@@ -163,6 +190,14 @@ Capybara::Screenshot.class_eval do
|
|
163
190
|
:not_supported
|
164
191
|
end
|
165
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
|
166
201
|
end
|
167
202
|
|
168
203
|
# Register filename prefix formatters
|
@@ -3,10 +3,6 @@ require "spec_helper"
|
|
3
3
|
describe "Using Capybara::Screenshot with Cucumber" do
|
4
4
|
include CommonSetup
|
5
5
|
|
6
|
-
before do
|
7
|
-
setup_aruba
|
8
|
-
end
|
9
|
-
|
10
6
|
let(:cmd) { 'cucumber' }
|
11
7
|
|
12
8
|
def run_failing_case(failure_message, code)
|
@@ -30,13 +26,13 @@ describe "Using Capybara::Screenshot with Cucumber" do
|
|
30
26
|
|
31
27
|
write_file('features/cucumber.feature', code)
|
32
28
|
|
33
|
-
run_simple_with_retry cmd
|
29
|
+
run_simple_with_retry cmd
|
34
30
|
|
35
31
|
expect(last_command_started.output).to_not match(/failed|failure/i) if options[:assert_all_passed]
|
36
32
|
end
|
37
33
|
|
38
34
|
it 'saves a screenshot on failure' do
|
39
|
-
run_failing_case %q{Unable to find 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
|
40
36
|
Feature: Failure
|
41
37
|
Scenario: Failure
|
42
38
|
Given I visit "/"
|
@@ -56,7 +52,7 @@ describe "Using Capybara::Screenshot with Cucumber" do
|
|
56
52
|
end
|
57
53
|
|
58
54
|
it 'saves a screenshot for the correct session for failures using_session' do
|
59
|
-
run_failing_case(%q{Unable to find 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)
|
60
56
|
Feature: Failure
|
61
57
|
Scenario: Failure in different session
|
62
58
|
Given I visit "/"
|
@@ -72,7 +68,7 @@ describe "Using Capybara::Screenshot with Cucumber" do
|
|
72
68
|
end
|
73
69
|
|
74
70
|
it 'on failure it prunes previous screenshots when strategy is set' do
|
75
|
-
run_failing_case %q{Unable to find 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
|
76
72
|
Feature: Prune
|
77
73
|
Scenario: Screenshots are pruned if strategy is set
|
78
74
|
Given I visit "/"
|
@@ -3,10 +3,6 @@ require "spec_helper"
|
|
3
3
|
describe "Using Capybara::Screenshot with MiniTest" do
|
4
4
|
include CommonSetup
|
5
5
|
|
6
|
-
before do
|
7
|
-
setup_aruba
|
8
|
-
end
|
9
|
-
|
10
6
|
def run_failing_case(code)
|
11
7
|
write_file('test_failure.rb', <<-RUBY)
|
12
8
|
#{ensure_load_paths_valid}
|
@@ -26,8 +22,8 @@ describe "Using Capybara::Screenshot with MiniTest" do
|
|
26
22
|
RUBY
|
27
23
|
|
28
24
|
cmd = 'bundle exec ruby test_failure.rb'
|
29
|
-
run_simple_with_retry cmd
|
30
|
-
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"}
|
31
27
|
end
|
32
28
|
|
33
29
|
it 'saves a screenshot on failure' do
|
@@ -3,10 +3,6 @@ require "spec_helper"
|
|
3
3
|
describe "Using Capybara::Screenshot with Test::Unit" do
|
4
4
|
include CommonSetup
|
5
5
|
|
6
|
-
before do
|
7
|
-
setup_aruba
|
8
|
-
end
|
9
|
-
|
10
6
|
def run_failing_case(code, integration_path = '.')
|
11
7
|
write_file("#{integration_path}/test_failure.rb", <<-RUBY)
|
12
8
|
#{ensure_load_paths_valid}
|
@@ -18,7 +14,7 @@ describe "Using Capybara::Screenshot with Test::Unit" do
|
|
18
14
|
|
19
15
|
#{setup_test_app}
|
20
16
|
Capybara::Screenshot.register_filename_prefix_formatter(:testunit) do | fault |
|
21
|
-
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"}
|
22
18
|
'my_screenshot'
|
23
19
|
end
|
24
20
|
|
@@ -32,8 +28,8 @@ describe "Using Capybara::Screenshot with Test::Unit" do
|
|
32
28
|
RUBY
|
33
29
|
|
34
30
|
cmd = "bundle exec ruby #{integration_path}/test_failure.rb"
|
35
|
-
run_simple_with_retry cmd
|
36
|
-
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"}
|
37
33
|
end
|
38
34
|
|
39
35
|
it "saves a screenshot on failure for any test in path 'test/integration'" do
|