Module: Daddy::Cucumber::Capture

Defined in:
lib/daddy/cucumber/helpers/capture.rb

Constant Summary collapse

REPORT_DIR =
File.join(feature_dir, 'reports')
IMAGE_DIR =
'images'
@@_screen_count =
0
@@_images =
[]

Instance Method Summary collapse

Instance Method Details

#capture(options = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/daddy/cucumber/helpers/capture.rb', line 18

def capture(options = {})
  options ||= {}
  options = {:title => options} if options.is_a?(String)

  pause
  return if ENV['FORMAT'] == 'junit'

  url = Rack::Utils.unescape(current_url)
    
  @@_screen_count += 1

  image = "#{IMAGE_DIR}/#{@@_screen_count}.png"
  page.driver.save_screenshot("#{REPORT_DIR}/#{image}", :full => true)

  image_tag = "<img class=\"screenshot\" src=\"#{image}\" title=\"#{options[:title]}\" alt=\"#{url}\"/>"

  if options[:flash]
    puts image_tag
  else
    @@_images << image_tag
  end
end

#flash_image_tagsObject



52
53
54
55
56
57
# File 'lib/daddy/cucumber/helpers/capture.rb', line 52

def flash_image_tags
  if @@_images.size > 0
    puts @@_images.join("\n")
    @@_images.clear
  end
end

#resize_window(width, height) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/daddy/cucumber/helpers/capture.rb', line 41

def resize_window(width, height)
  case Capybara.current_driver
  when :poltergeist
    Capybara.current_session.driver.resize(width, height)
  when :selenium
    Capybara.current_session.driver.browser.manage.window.resize_to(width, height)
  when :webkit
    # TODO
  end
end