Module: Capybara::Screenshot
- Defined in:
- lib/capybara-screenshot.rb,
lib/capybara-screenshot/rspec.rb,
lib/capybara-screenshot/saver.rb,
lib/capybara-screenshot/pruner.rb,
lib/capybara-screenshot/version.rb,
lib/capybara-screenshot/s3_saver.rb,
lib/capybara-screenshot/testunit.rb,
lib/capybara-screenshot/callbacks.rb,
lib/capybara-screenshot/rspec/base_reporter.rb,
lib/capybara-screenshot/rspec/json_reporter.rb,
lib/capybara-screenshot/rspec/text_reporter.rb,
lib/capybara-screenshot/rspec/html_link_reporter.rb,
lib/capybara-screenshot/rspec/html_embed_reporter.rb,
lib/capybara-screenshot/rspec/textmate_link_reporter.rb
Defined Under Namespace
Modules: Callbacks, MiniTestPlugin, RSpec, Spinach Classes: Pruner, S3Saver, Saver
Constant Summary collapse
- VERSION =
'1.0.27'
Class Attribute Summary collapse
-
.append_random ⇒ Object
Returns the value of attribute append_random.
-
.append_timestamp ⇒ Object
Returns the value of attribute append_timestamp.
-
.autosave_on_failure ⇒ Object
Returns the value of attribute autosave_on_failure.
-
.filename_prefix_formatters ⇒ Object
Returns the value of attribute filename_prefix_formatters.
- .final_session_name ⇒ Object
-
.prune_strategy ⇒ Object
Returns the value of attribute prune_strategy.
-
.registered_drivers ⇒ Object
Returns the value of attribute registered_drivers.
-
.s3_configuration ⇒ Object
Returns the value of attribute s3_configuration.
-
.s3_object_configuration ⇒ Object
Returns the value of attribute s3_object_configuration.
-
.testunit_paths ⇒ Object
Returns the value of attribute testunit_paths.
-
.webkit_options ⇒ Object
Returns the value of attribute webkit_options.
Class Method Summary collapse
- .after_save_html(&block) ⇒ Object
- .after_save_screenshot(&block) ⇒ Object
- .append_screenshot_path=(value) ⇒ Object
- .capybara_root ⇒ Object
-
.capybara_tmp_path ⇒ Object
If the path isn’t set, default to the current directory.
-
.capybara_tmp_path=(path) ⇒ Object
Configure the path unless ‘.’.
- .filename_prefix_for(test_type, test) ⇒ Object
- .new_saver(*args) ⇒ Object
-
.prune(options = {}) ⇒ Object
Prune screenshots based on prune_strategy Will run only once unless force:true.
- .register_driver(driver, &block) ⇒ Object
- .register_filename_prefix_formatter(test_type, &block) ⇒ Object
-
.reset_prune_history ⇒ Object
Reset prune history allowing further prunining on next failure.
- .screenshot_and_open_image(filename_prefix: nil) ⇒ Object (also: screen_shot_and_open_image)
- .screenshot_and_save_page(filename_prefix: nil, save_html: true) ⇒ Object (also: screen_shot_and_save_page)
Class Attribute Details
.append_random ⇒ Object
Returns the value of attribute append_random.
8 9 10 |
# File 'lib/capybara-screenshot.rb', line 8 def append_random @append_random end |
.append_timestamp ⇒ Object
Returns the value of attribute append_timestamp.
7 8 9 |
# File 'lib/capybara-screenshot.rb', line 7 def @append_timestamp end |
.autosave_on_failure ⇒ Object
Returns the value of attribute autosave_on_failure.
4 5 6 |
# File 'lib/capybara-screenshot.rb', line 4 def autosave_on_failure @autosave_on_failure end |
.filename_prefix_formatters ⇒ Object
Returns the value of attribute filename_prefix_formatters.
6 7 8 |
# File 'lib/capybara-screenshot.rb', line 6 def filename_prefix_formatters @filename_prefix_formatters end |
.final_session_name ⇒ Object
82 83 84 |
# File 'lib/capybara-screenshot.rb', line 82 def self.final_session_name @final_session_name || Capybara.session_name || :default end |
.prune_strategy ⇒ Object
Returns the value of attribute prune_strategy.
11 12 13 |
# File 'lib/capybara-screenshot.rb', line 11 def prune_strategy @prune_strategy end |
.registered_drivers ⇒ Object
Returns the value of attribute registered_drivers.
5 6 7 |
# File 'lib/capybara-screenshot.rb', line 5 def registered_drivers @registered_drivers end |
.s3_configuration ⇒ Object
Returns the value of attribute s3_configuration.
12 13 14 |
# File 'lib/capybara-screenshot.rb', line 12 def s3_configuration @s3_configuration end |
.s3_object_configuration ⇒ Object
Returns the value of attribute s3_object_configuration.
13 14 15 |
# File 'lib/capybara-screenshot.rb', line 13 def s3_object_configuration @s3_object_configuration end |
.testunit_paths ⇒ Object
Returns the value of attribute testunit_paths.
5 6 7 |
# File 'lib/capybara-screenshot/testunit.rb', line 5 def testunit_paths @testunit_paths end |
.webkit_options ⇒ Object
Returns the value of attribute webkit_options.
9 10 11 |
# File 'lib/capybara-screenshot.rb', line 9 def @webkit_options end |
Class Method Details
.after_save_html(&block) ⇒ Object
110 111 112 |
# File 'lib/capybara-screenshot.rb', line 110 def self.after_save_html &block Saver.after_save_html(&block) end |
.after_save_screenshot(&block) ⇒ Object
114 115 116 |
# File 'lib/capybara-screenshot.rb', line 114 def self.after_save_screenshot &block Saver.after_save_screenshot(&block) end |
.append_screenshot_path=(value) ⇒ Object
26 27 28 29 30 |
# File 'lib/capybara-screenshot.rb', line 26 def self.append_screenshot_path=(value) $stderr.puts "WARNING: Capybara::Screenshot.append_screenshot_path is deprecated. " + "Please use Capybara::Screenshot::RSpec.add_link_to_screenshot_for_failed_examples instead." RSpec.add_link_to_screenshot_for_failed_examples = value end |
.capybara_root ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/capybara-screenshot.rb', line 62 def self. @capybara_root ||= if defined?(::Rails) && ::Rails.respond_to?(:root) && ::Rails.root.present? ::Rails.root.join elsif defined?(Padrino) File.(, Padrino.root) elsif defined?(Sinatra) File.join(Sinatra::Application.root, ) else end.to_s end |
.capybara_tmp_path ⇒ Object
If the path isn’t set, default to the current directory
121 122 123 124 125 126 127 128 129 |
# File 'lib/capybara-screenshot.rb', line 121 def self. # `#save_and_open_page_path` is deprecated # https://github.com/jnicklas/capybara/blob/48ab1ede946dec2250a2d1d8cbb3313f25096456/History.md#L37 if Capybara.respond_to?(:save_path) Capybara.save_path else Capybara.save_and_open_page_path end || '.' end |
.capybara_tmp_path=(path) ⇒ Object
Configure the path unless ‘.’
132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/capybara-screenshot.rb', line 132 def self.(path) return if path == '.' # `#save_and_open_page_path` is deprecated # https://github.com/jnicklas/capybara/blob/48ab1ede946dec2250a2d1d8cbb3313f25096456/History.md#L37 if Capybara.respond_to?(:save_path) Capybara.save_path = path else Capybara.save_and_open_page_path = path end end |
.filename_prefix_for(test_type, test) ⇒ Object
56 57 58 59 60 |
# File 'lib/capybara-screenshot.rb', line 56 def self.filename_prefix_for(test_type, test) filename_prefix_formatters.fetch(test_type) { |key| filename_prefix_formatters[:default] }.call(test) end |
.new_saver(*args) ⇒ Object
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/capybara-screenshot.rb', line 99 def self.new_saver(*args) saver = Saver.new(*args) unless s3_configuration.empty? require 'capybara-screenshot/s3_saver' saver = S3Saver.new_with_configuration(saver, s3_configuration, s3_object_configuration) end return saver end |
.prune(options = {}) ⇒ Object
Prune screenshots based on prune_strategy Will run only once unless force:true
88 89 90 91 92 |
# File 'lib/capybara-screenshot.rb', line 88 def self.prune( = {}) reset_prune_history if [:force] Capybara::Screenshot::Pruner.new(Capybara::Screenshot.prune_strategy).prune_old_screenshots unless @pruned_previous_screenshots @pruned_previous_screenshots = true end |
.register_driver(driver, &block) ⇒ Object
74 75 76 |
# File 'lib/capybara-screenshot.rb', line 74 def self.register_driver(driver, &block) self.registered_drivers[driver] = block end |
.register_filename_prefix_formatter(test_type, &block) ⇒ Object
78 79 80 |
# File 'lib/capybara-screenshot.rb', line 78 def self.register_filename_prefix_formatter(test_type, &block) self.filename_prefix_formatters[test_type] = block end |
.reset_prune_history ⇒ Object
Reset prune history allowing further prunining on next failure
95 96 97 |
# File 'lib/capybara-screenshot.rb', line 95 def self.reset_prune_history @pruned_previous_screenshots = nil end |
.screenshot_and_open_image(filename_prefix: nil) ⇒ Object Also known as: screen_shot_and_open_image
41 42 43 44 45 46 47 48 49 |
# File 'lib/capybara-screenshot.rb', line 41 def self.screenshot_and_open_image(filename_prefix: nil) require "launchy" saver = new_saver(Capybara, Capybara.page, false, filename_prefix) if saver.save Launchy.open saver.screenshot_path {:html => nil, :image => saver.screenshot_path} end end |
.screenshot_and_save_page(filename_prefix: nil, save_html: true) ⇒ Object Also known as: screen_shot_and_save_page
32 33 34 35 36 37 38 39 |
# File 'lib/capybara-screenshot.rb', line 32 def self.screenshot_and_save_page(filename_prefix: nil, save_html: true) saver = new_saver(Capybara, Capybara.page, save_html, filename_prefix) if saver.save {:html => saver.html_path, :image => saver.screenshot_path} elsif !save_html warn 'WARN: no screenshot has been saved. You should configure the driver used by Capybara to save images.' end end |