Module: Screenshot

Defined in:
lib/utils/screenshot.rb

Overview

Created on 07 May 2019 @author: Andy Perrett

Versions: 1.0 - Baseline

screenshot.rb - a screenshot save function

Class Method Summary collapse

Class Method Details

.save_screenshot(test_step_idx) ⇒ Object

create screenshot filename and save the screenshot if the test has failed.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/utils/screenshot.rb', line 14

def self.save_screenshot(test_step_idx)
  time = Time.now.strftime('%H%M')
  sc_dir = CreateDirectories.construct_testspecdirs

  sc_file_name = "#{sc_dir}/Test_ID-#{JsonParser.test_id.delete(' ')}"\
                    "_Test_step-#{test_step_idx}_Failed_#{time}.png"

  # Screenshot capture for websites
  Browser.b.screenshot.save sc_file_name
  MyLog.log.info("Screenshot saved to: #{sc_file_name} \n")
  sc_file_name
rescue StandardError => e
  # construct the error message from custom text and the actual system
  # error message (converted to a string).
  MyLog.log.warn("Error saving the screenshot: #{sc_file_name}   #{e}")
end