Module: Calabash::Cucumber::FailureHelpers

Included in:
Core, TestsHelpers
Defined in:
lib/calabash-cucumber/failure_helpers.rb

Instance Method Summary collapse

Instance Method Details

#fail(msg = 'Error. Check log for details.', options = {:prefix => nil, :name => nil, :label => nil}) ⇒ Object



41
42
43
# File 'lib/calabash-cucumber/failure_helpers.rb', line 41

def fail(msg='Error. Check log for details.', options={:prefix => nil, :name => nil, :label => nil})
  screenshot_and_raise(msg, options)
end

#screenshot(options = {:prefix => nil, :name => nil}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/calabash-cucumber/failure_helpers.rb', line 7

def screenshot(options={:prefix => nil, :name => nil})
  prefix = options[:prefix]
  name = options[:name]

  @@screenshot_count ||= 0
  res = http({:method => :get, :path => 'screenshot'})
  prefix = prefix || ENV['SCREENSHOT_PATH'] || ''
  if name.nil?
    name = 'screenshot'
  else
    if File.extname(name).downcase == '.png'
      name = name.split('.png')[0]
    end
  end

  path = "#{prefix}#{name}_#{@@screenshot_count}.png"
  File.open(path, 'wb') do |f|
    f.write res
  end
  @@screenshot_count += 1
  path
end

#screenshot_and_raise(msg, options = {:prefix => nil, :name => nil, :label => nil}) ⇒ Object



36
37
38
39
# File 'lib/calabash-cucumber/failure_helpers.rb', line 36

def screenshot_and_raise(msg, options={:prefix => nil, :name => nil, :label => nil})
  screenshot_embed(options)
  raise(msg)
end

#screenshot_embed(options = {:prefix => nil, :name => nil, :label => nil}) ⇒ Object



30
31
32
33
34
# File 'lib/calabash-cucumber/failure_helpers.rb', line 30

def screenshot_embed(options={:prefix => nil, :name => nil, :label => nil})
  path = screenshot(options)
  filename = options[:label] || File.basename(path)
  embed(path, 'image/png', filename)
end