Module: HookHelper

Defined in:
lib/watirmark/cucumber/hook_helper.rb

Class Method Summary collapse

Class Method Details

.clear_post_errorsObject



4
5
6
# File 'lib/watirmark/cucumber/hook_helper.rb', line 4

def clear_post_errors
  Watirmark::Session.instance.post_failure = nil
end

.serialize_modelsObject



31
32
33
34
35
36
# File 'lib/watirmark/cucumber/hook_helper.rb', line 31

def serialize_models
  return unless Watirmark::Configuration.instance.use_cached_models
  Dir.mkdir("cache") unless Dir.exists? "cache"
  File.unlink "cache/DataModels" if File.exists? "cache/DataModels"
  File.open("cache/DataModels", "wb") { |f| f.print Marshal::dump(DataModels) }
end

.take_screenshotObject



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

def take_screenshot
  image = "#{Time.now.to_i}-#{UUID.new.generate(:compact)}.png"
  path = "reports/screenshots"
  file = "#{path}/#{image}"
  FileUtils.mkdir_p path unless File.directory? path
  begin
    Page.browser.screenshot.save file
    data = File.open(file, 'rb') { |f| f.read }
    data = Base64.encode64(data)
  rescue Exception => e
    Watirmark.logger.warn("Screenshot was not taken due to an exception")
    Watirmark.logger.warn(e.to_s)
    Watirmark.logger.warn(e.backtrace)
  end

  [data, 'image/png']
end

.trap_post_errors(&block) ⇒ Object



8
9
10
# File 'lib/watirmark/cucumber/hook_helper.rb', line 8

def trap_post_errors(&block)
  Watirmark::Session.instance.catch_post_failures(&block)
end