Class: Screenpress::Saver
- Inherits:
-
Object
- Object
- Screenpress::Saver
- Defined in:
- lib/screenpress/saver.rb
Defined Under Namespace
Classes: Proxy
Instance Attribute Summary collapse
-
#capybara ⇒ Object
readonly
Returns the value of attribute capybara.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
Instance Method Summary collapse
- #ensure_directory ⇒ Object
-
#initialize(filename, capybara = nil, page = nil) ⇒ Saver
constructor
A new instance of Saver.
- #save ⇒ Object
- #save_screenshot ⇒ Object
- #tmp_filename ⇒ Object
Constructor Details
#initialize(filename, capybara = nil, page = nil) ⇒ Saver
Returns a new instance of Saver.
7 8 9 10 11 |
# File 'lib/screenpress/saver.rb', line 7 def initialize(filename, = nil, page = nil) @capybara = || Capybara @page = page || @capybara.page @filename = filename end |
Instance Attribute Details
#capybara ⇒ Object (readonly)
Returns the value of attribute capybara.
5 6 7 |
# File 'lib/screenpress/saver.rb', line 5 def @capybara end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
5 6 7 |
# File 'lib/screenpress/saver.rb', line 5 def filename @filename end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
5 6 7 |
# File 'lib/screenpress/saver.rb', line 5 def page @page end |
Instance Method Details
#ensure_directory ⇒ Object
44 45 46 47 48 |
# File 'lib/screenpress/saver.rb', line 44 def ensure_directory folder = File.dirname(filename) return if File.directory?(folder) FileUtils.mkdir_p(folder) end |
#save ⇒ Object
13 14 15 16 17 |
# File 'lib/screenpress/saver.rb', line 13 def save # if current_path empty then nothing to screen shot as browser has not loaded any URL return false if .current_path.to_s.empty? save_screenshot end |
#save_screenshot ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/screenpress/saver.rb', line 19 def save_screenshot tmp_file = self.tmp_filename # settings to nil because of issues in some version of capybara old_path = Capybara.save_and_open_page_path Capybara.save_and_open_page_path = nil ensure_directory return false unless Screenpress::Saver::Proxy.save!(.current_driver, page.driver, tmp_file) # is it different? compare = Screenpress::Compare.new(filename, tmp_file, Screenpress.config.threshold) if compare.same? File.delete(tmp_file) else FileUtils.mv(tmp_file, filename) end return true rescue Exception => e File.delete(tmp_file) if tmp_file && File.exists?(tmp_file) raise e end |
#tmp_filename ⇒ Object
50 51 52 53 54 |
# File 'lib/screenpress/saver.rb', line 50 def tmp_filename tmp_dir = Screenpress.config.full_tmp_path.to_s tmp_file = "#{tmp_dir}/screenpress_#{File.basename(filename)}" tmp_file end |