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
-
#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
#screenshot_path ⇒ String
Default screenshot path. Can be set with #screenshot_path=.
33 34 35 |
# File 'lib/qat/web/browser/screenshot.rb', line 33 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.
40 41 42 |
# File 'lib/qat/web/browser/screenshot.rb', line 40 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.exists? path path = page.save_screenshot path log.info {"Screenshot available"} path rescue Capybara::NotSupportedByDriverError log.warn {"Driver #{page.mode} does not support screenshots!"} return nil end |