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.

Since:

  • 1.0.0

Instance Method Summary collapse

Instance Method Details

#screenshot_pathString

Default screenshot path. Can be set with #screenshot_path=.

Returns:

  • (String)

    Screenshot path

Since:

  • 1.0.0



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.

Parameters:

  • value (String)

    Screenshot path

Since:

  • 1.0.0



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.

Parameters:

  • page (Capybara::Session) (defaults to: Capybara.current_session)

    Browser to take screenshot from

  • path (String) (defaults to: screenshot_path)

    File path to save screenshot file

Returns:

  • (String/NilClass)

    File path to where the screenshot file was saved or nil if the browser doesn’t support screenshots

Since:

  • 1.0.0



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