Module: Calabash::Cucumber::TestsHelpers

Includes:
Core
Included in:
KeyboardHelpers, Operations, WaitHelpers
Defined in:
lib/calabash-cucumber/tests_helpers.rb

Constant Summary

Constants included from Core

Core::CAL_HTTP_RETRY_COUNT, Core::DATA_PATH, Core::RETRYABLE_ERRORS

Instance Method Summary collapse

Methods included from Core

#backdoor, #background, #calabash_exit, #cell_swipe, #client_version, #current_rotation, #default_device, #flash, #http, #init_request, #interpolate, #load_playback_data, #load_recording, #macro, #make_http_request, #map, #move_wheel, #perform, #picker, #pinch, #playback, #prepare_dialog_action, #query, #query_all, #record_begin, #record_end, #recording_name_for, #rotate, #scroll, #scroll_to_cell, #scroll_to_row, #scroll_to_row_with_mark, #send_uia_command, #server_version, #start_test_server_in_background, #stop_test_server, #swipe, #touch, #url_for

Instance Method Details

#check_element_does_not_exist(query) ⇒ Object


44
45
46
47
48
# File 'lib/calabash-cucumber/tests_helpers.rb', line 44

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

#check_element_exists(query) ⇒ Object


38
39
40
41
42
# File 'lib/calabash-cucumber/tests_helpers.rb', line 38

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

#check_view_with_mark_exists(expected_mark) ⇒ Object


50
51
52
# File 'lib/calabash-cucumber/tests_helpers.rb', line 50

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

#classes(uiquery, *args) ⇒ Object


22
23
24
# File 'lib/calabash-cucumber/tests_helpers.rb', line 22

def classes(uiquery,*args)
  query_map(uiquery,:class,*args)
end

#each_cell(opts = {:query => "tableView", :post_scroll => 0.3, :animate => true}, &block) ⇒ Object


63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/calabash-cucumber/tests_helpers.rb', line 63

def each_cell(opts={:query => "tableView", :post_scroll => 0.3, :animate => true}, &block)
  uiquery = opts[:query] || "tableView"
  skip = opts[:skip_if]
  check_element_exists(uiquery)
  secs = query(uiquery,:numberOfSections).first
  secs.times do |sec|
    rows = query(uiquery,{:numberOfRowsInSection => sec}).first
    rows.times do |row|
      next if skip and skip.call(row,sec)
      scroll_opts = {:section => sec, :row => row}.merge(opts)
      scroll_to_cell(scroll_opts)
      sleep(opts[:post_scroll]) if opts[:post_scroll] and opts[:post_scroll] > 0
      yield(row, sec)
    end
  end
end

#each_cell_and_back(opts = {:query => "tableView", :post_scroll => 0.3, :post_back => 0.5, :post_tap_cell => 0.3, :animate => true}, &block) ⇒ Object


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/calabash-cucumber/tests_helpers.rb', line 80

def each_cell_and_back(opts={:query => "tableView",
                             :post_scroll => 0.3,
                             :post_back => 0.5,
                             :post_tap_cell => 0.3,
                             :animate => true}, &block)
  back_query = opts[:back_query] || "navigationItemButtonView"
  post_tap_cell = opts[:post_tap_cell] || 0.3
  post_back = opts[:post_back] || 0.6


  each_cell(opts) do |row, sec|
    touch("tableViewCell indexPath:#{row},#{sec}")
    wait_for_elements_exist([back_query])
    sleep(post_tap_cell) if post_tap_cell > 0

    yield(row,sec) if block_given?

    touch(back_query)

    sleep(post_back) if post_back > 0

  end
end

#element_does_not_exist(uiquery) ⇒ Object


26
27
28
# File 'lib/calabash-cucumber/tests_helpers.rb', line 26

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

#element_exists(uiquery) ⇒ Object


30
31
32
# File 'lib/calabash-cucumber/tests_helpers.rb', line 30

def element_exists(uiquery)
  not element_does_not_exist(uiquery)
end

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


59
60
61
# File 'lib/calabash-cucumber/tests_helpers.rb', line 59

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

8
9
10
11
12
13
14
15
16
# File 'lib/calabash-cucumber/tests_helpers.rb', line 8

def navigation_path(*args)

  #navigation_path(
  #    [:a , 2],
  #    [""],
  #)


end

#query_map(uiquery, prop, *args) ⇒ Object


18
19
20
# File 'lib/calabash-cucumber/tests_helpers.rb', line 18

def query_map(uiquery,prop, *args)
  query(uiquery,*args).map {|o| o[prop.to_s]}
end

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


110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/calabash-cucumber/tests_helpers.rb', line 110

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


54
55
56
57
# File 'lib/calabash-cucumber/tests_helpers.rb', line 54

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


105
106
107
108
# File 'lib/calabash-cucumber/tests_helpers.rb', line 105

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

#view_with_mark_exists(expected_mark) ⇒ Object


34
35
36
# File 'lib/calabash-cucumber/tests_helpers.rb', line 34

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