Sha256: f470068e55210f3d47188c5c4e1f28daf4fdb581ec8f797c46febd2b3be4ed06

Contents?: true

Size: 1.54 KB

Versions: 19

Compression:

Stored size: 1.54 KB

Contents

require 'calabash-cucumber/core'

module Calabash
  module Cucumber
    module TestsHelpers
      include Calabash::Cucumber::Core

      def element_does_not_exist(uiquery)
        query(uiquery).empty?
      end

      def element_exists(uiquery)
        not element_does_not_exist(uiquery)
      end

      def view_with_mark_exists(expected_mark)
        element_exists("view marked:'#{expected_mark}'")
      end

      def check_element_exists(query)
        if not element_exists(query)
          screenshot_and_raise "No element found for query: #{query}"
        end
      end

      def check_element_does_not_exist(query)
        if element_exists(query)
          screenshot_and_raise "Expected no elements to match query: #{query}"
        end
      end

      def check_view_with_mark_exists(expected_mark)
        check_element_exists("view marked:'#{expected_mark}'")
      end

      def screenshot_and_raise(msg, prefix=nil, name=nil)
        screenshot(prefix, name)
        raise(msg)
      end

      def fail(msg="Error. Check log for details.", prefix=nil, name=nil)
        screenshot_and_raise(msg, prefix, name)
      end

      def screenshot(prefix=nil, name=nil)
        res = http({:method => :get, :path => 'screenshot'})
        prefix = prefix || ENV['SCREENSHOT_PATH'] || ""
        name = "screenshot_#{CALABASH_COUNT[:step_line]}.png" if name.nil?
        path = "#{prefix}#{name}"
        File.open(path, 'wb') do |f|
          f.write res
        end
        puts "Saved screenshot: #{path}"
        path
      end

    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
calabash-cucumber-0.9.96 lib/calabash-cucumber/tests_helpers.rb
calabash-cucumber-0.9.95 lib/calabash-cucumber/tests_helpers.rb
calabash-cucumber-0.9.94 lib/calabash-cucumber/tests_helpers.rb
calabash-cucumber-0.9.93 lib/calabash-cucumber/tests_helpers.rb
calabash-cucumber-0.9.92 lib/calabash-cucumber/tests_helpers.rb
calabash-cucumber-0.9.91 lib/calabash-cucumber/tests_helpers.rb
calabash-cucumber-0.9.90 lib/calabash-cucumber/tests_helpers.rb
calabash-cucumber-0.9.89 lib/calabash-cucumber/tests_helpers.rb
calabash-cucumber-0.9.88 lib/calabash-cucumber/tests_helpers.rb
calabash-cucumber-0.9.87 lib/calabash-cucumber/tests_helpers.rb
calabash-cucumber-0.9.86 lib/calabash-cucumber/tests_helpers.rb
calabash-cucumber-0.9.85 lib/calabash-cucumber/tests_helpers.rb
calabash-cucumber-0.9.84 lib/calabash-cucumber/tests_helpers.rb
calabash-cucumber-0.9.82 lib/calabash-cucumber/tests_helpers.rb
calabash-cucumber-0.9.80 lib/calabash-cucumber/tests_helpers.rb
calabash-cucumber-0.9.80.pre.5 lib/calabash-cucumber/tests_helpers.rb
calabash-cucumber-0.9.80.pre.4 lib/calabash-cucumber/tests_helpers.rb
calabash-cucumber-0.9.80.pre.2 lib/calabash-cucumber/tests_helpers.rb
calabash-cucumber-0.9.80.pre.1 lib/calabash-cucumber/tests_helpers.rb