Module: Calabash::Cucumber::FailureHelpers
- Included in:
- Core, TestsHelpers
- Defined in:
- lib/calabash-cucumber/failure_helpers.rb
Overview
A collection of methods that help you handle Step failures.
Instance Method Summary collapse
-
#fail(msg = 'Error. Check log for details.', options = {:prefix => nil, :name => nil, :label => nil}) ⇒ Object
Calls ‘screenshot_and_raise(msg,options)`.
-
#screenshot(options = {:prefix => nil, :name => nil}) ⇒ String
Generates a screenshot of the app UI and saves to a file (prefer ‘screenshot_embed`).
-
#screenshot_and_raise(msg, options = {:prefix => nil, :name => nil, :label => nil}) ⇒ Object
Generates a screenshot of the app UI by calling screenshot_embed and raises an error.
-
#screenshot_embed(options = {:prefix => nil, :name => nil, :label => nil}) ⇒ String
Generates a screenshot of the app UI and embeds the screenshots in all active cucumber reporters (using ‘embed`).
Instance Method Details
#fail(msg = 'Error. Check log for details.', options = {:prefix => nil, :name => nil, :label => nil}) ⇒ Object
Calls ‘screenshot_and_raise(msg,options)`
91 92 93 |
# File 'lib/calabash-cucumber/failure_helpers.rb', line 91 def fail(msg='Error. Check log for details.', ={:prefix => nil, :name => nil, :label => nil}) screenshot_and_raise(msg, ) end |
#screenshot(options = {:prefix => nil, :name => nil}) ⇒ String
deprecated the current behavior of SCREENSHOT_PATH; it is confusing
Generates a screenshot of the app UI and saves to a file (prefer ‘screenshot_embed`). Increments a global counter of screenshots and adds the count to the filename (to ensure uniqueness).
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/calabash-cucumber/failure_helpers.rb', line 19 def screenshot(={:prefix => nil, :name => nil}) prefix = [:prefix] name = [: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
Generates a screenshot of the app UI by calling screenshot_embed and raises an error. Increments a global counter of screenshots and adds the count to the filename (to ensure uniqueness).
77 78 79 80 |
# File 'lib/calabash-cucumber/failure_helpers.rb', line 77 def screenshot_and_raise(msg, ={:prefix => nil, :name => nil, :label => nil}) () raise(msg) end |
#screenshot_embed(options = {:prefix => nil, :name => nil, :label => nil}) ⇒ String
Generates a screenshot of the app UI and embeds the screenshots in all active cucumber reporters (using ‘embed`). Increments a global counter of screenshots and adds the count to the filename (to ensure uniqueness).
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/calabash-cucumber/failure_helpers.rb', line 51 def (={:prefix => nil, :name => nil, :label => nil}) path = screenshot() filename = [:label] || File.basename(path) if self.respond_to?(:embed) begin (path, 'image/png', filename) rescue NoMethodError attach(path, 'image/png') end else RunLoop.log_info2("Embed is not available in this context. Will not embed.") end true end |