Module: QAT::Web::Browser::Screenshot
- Extended by:
- Screenshot
- Includes:
- Logger
- Included in:
- Screenshot
- Defined in:
- lib/qat/web/browser/screenshot.rb
Overview
Module to handle browser screenshots.
Instance Method Summary collapse
-
#read_screenshot_file(page, image_path) ⇒ Object
Helper for reading file, in cucumber 6 this could be reverted to path directly.
- #screenshot_filename ⇒ Object
-
#screenshot_path ⇒ String
Default screenshot path.
-
#screenshot_path=(value) ⇒ Object
Set new default screenshot path.
-
#take_screenshot(page = Capybara.current_session, path = screenshot_path) ⇒ String/NilClass
Function to take a browser screenshot.
Instance Method Details
#read_screenshot_file(page, image_path) ⇒ Object
Helper for reading file, in cucumber 6 this could be reverted to path directly
31 32 33 34 |
# File 'lib/qat/web/browser/screenshot.rb', line 31 def read_screenshot_file page, image_path file = page.save_screenshot image_path File.open file end |
#screenshot_filename ⇒ Object
36 37 38 |
# File 'lib/qat/web/browser/screenshot.rb', line 36 def screenshot_filename File.basename(@screenshot_path) end |
#screenshot_path ⇒ String
Default screenshot path. Can be set with #screenshot_path=.
43 44 45 |
# File 'lib/qat/web/browser/screenshot.rb', line 43 def screenshot_path @screenshot_path || ::File.join('public', "browser_#{Time.new.strftime("%H%M%S%L")}.png") end |
#screenshot_path=(value) ⇒ Object
Set new default screenshot path.
50 51 52 |
# File 'lib/qat/web/browser/screenshot.rb', line 50 def screenshot_path= value @screenshot_path = value end |
#take_screenshot(page = Capybara.current_session, path = screenshot_path) ⇒ String/NilClass
Function to take a browser screenshot. Will handle the usage of driver that don’t support screenshots.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/qat/web/browser/screenshot.rb', line 19 def take_screenshot page = Capybara.current_session , path = screenshot_path log.info { "Saving screenshot to #{path}" } raise ArgumentError.new "File #{path} already exists! Choose another filename" if ::File.exist? path path = read_screenshot_file page, path log.info { "Screenshot available" } path rescue Capybara::NotSupportedByDriverError log.warn {"Driver #{page.mode} does not support screenshots!"} return nil end |