Sha256: b2bbb181bbf5c3cf0c8c1834d355ba8fbd448d9988a9fc2dbe7aa7533ec8ef5e

Contents?: true

Size: 1.21 KB

Versions: 5

Compression:

Stored size: 1.21 KB

Contents

module Calabash
  module Cucumber
    module FailureHelpers

      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

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

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

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

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
calabash-cucumber-0.9.163.pre11 lib/calabash-cucumber/failure_helpers.rb
calabash-cucumber-0.9.163.pre10 lib/calabash-cucumber/failure_helpers.rb
calabash-cucumber-0.9.163.pre9 lib/calabash-cucumber/failure_helpers.rb
calabash-cucumber-0.9.163.pre8 lib/calabash-cucumber/failure_helpers.rb
calabash-cucumber-0.9.163.pre7 lib/calabash-cucumber/failure_helpers.rb