Module: Calabash::Cucumber::Operations

Includes:
Core, DatePicker, IPad, KeyboardHelpers, KeychainHelpers, Logging, TestsHelpers, WaitHelpers, Test::Unit::Assertions
Included in:
IBase
Defined in:
lib/calabash-cucumber/operations.rb

Constant Summary

Constants included from DatePicker

DatePicker::OBJC_DATE_AND_TIME_FMT, DatePicker::RUBY_DATE_AND_TIME_FMT, DatePicker::UI_DATE_PICKER_MODE_COUNT_DOWN_TIMER, DatePicker::UI_DATE_PICKER_MODE_DATE, DatePicker::UI_DATE_PICKER_MODE_DATE_AND_TIME, DatePicker::UI_DATE_PICKER_MODE_TIME

Constants included from PlaybackHelpers

PlaybackHelpers::DATA_PATH

Constants included from Logging

Logging::CALABASH_NO_DEPRECATION

Constants included from KeyboardHelpers

KeyboardHelpers::KEYPLANE_NAMES, KeyboardHelpers::UIA_SUPPORTED_CHARS

Constants included from WaitHelpers

WaitHelpers::CALABASH_CONDITIONS, WaitHelpers::CLIENT_TIMEOUT_ADDITION, WaitHelpers::DEFAULT_OPTS

Instance Method Summary collapse

Methods included from IPad

#ensure_ipad_emulation_1x, #ensure_ipad_emulation_scale

Methods included from DatePicker

#args_for_change_date_on_picker, #countdown_mode?, #date_and_time_mode?, #date_mode?, #date_picker_mode, #date_time_from_picker, #maximum_date_time_from_picker, #minimum_date_time_from_picker, #picker_set_date_time, #query_string_for_picker, #should_see_date_picker, #time_mode?

Methods included from Core

#_debug_level_response, #backdoor, #calabash_exit, #cell_swipe, #client_version, #console_attach, #double_tap, #extract_query_and_options, #flash, #flick, #launcher, #location_for_place, #locations_for_place, #macro, #move_wheel, #pan, #picker, #pinch, #prepare_query_options, #q, #query, #query_action_with_options, #query_all, #scroll, #scroll_to_cell, #scroll_to_collection_view_item, #scroll_to_collection_view_item_with_mark, #scroll_to_row, #scroll_to_row_with_mark, #send_app_to_background, #server_debug_level, #server_version, #set_location, #set_server_debug_level, #shutdown_test_server, #start_test_server_in_background, #stop_test_server, #swipe, #t, #touch, #touch_hold, #two_finger_tap, #wait_tap

Methods included from PlaybackHelpers

#find_compatible_recording, #interpolate, #load_playback_data, #load_recording, #playback, #playback_file_directories, #record_begin, #record_end, #recording_name_for

Methods included from Logging

#_deprecated, #calabash_info, #calabash_warn, #debug_logging?, #full_console_logging?, #no_deprecation_warnings?

Methods included from RotationHelpers

#rotate, #rotate_home_button_to, #rotation_candidates

Methods included from StatusBarHelpers

#device_orientation, #landscape?, #portrait?, #status_bar_orientation

Methods included from UIA

#escape_uia_string, #send_uia_command, #uia, #uia_call, #uia_call_method, #uia_call_windows, #uia_double_tap, #uia_double_tap_mark, #uia_double_tap_offset, #uia_element_does_not_exist?, #uia_element_exists?, #uia_enter, #uia_flick_offset, #uia_handle_command, #uia_names, #uia_pan, #uia_pan_offset, #uia_pinch, #uia_pinch_offset, #uia_query, #uia_query_el, #uia_query_windows, #uia_screenshot, #uia_scroll_to, #uia_send_app_to_background, #uia_serialize_argument, #uia_serialize_arguments, #uia_serialize_command, #uia_set_location, #uia_swipe, #uia_swipe_offset, #uia_tap, #uia_tap_mark, #uia_tap_offset, #uia_touch_hold, #uia_touch_hold_offset, #uia_two_finger_tap, #uia_two_finger_tap_offset, #uia_type_string, #uia_wait_tap

Methods included from Map

#assert_map_results, #map, #raw_map

Methods included from FailureHelpers

#fail, #screenshot, #screenshot_and_raise, #screenshot_embed

Methods included from QueryHelpers

#escape_quotes, #point_from

Methods included from ConnectionHelpers

#connection, #http

Methods included from EnvironmentHelpers

#default_device, #device_family_iphone?, #ios5?, #ios6?, #ios7?, #ipad?, #iphone?, #iphone_4in?, #iphone_5?, #iphone_app_emulated_on_ipad?, #ipod?, #simulator?, #uia_available?, #uia_not_available?, #xamarin_test_cloud?

Methods included from KeychainHelpers

#_keychain_get, #_keychain_post, #keychain_accounts, #keychain_accounts_for_service, #keychain_clear, #keychain_clear_accounts_for_service, #keychain_delete_password, #keychain_password, #keychain_set_password

Methods included from KeyboardHelpers

#_current_keyplane, #_do_keyplane, #_ensure_can_enter_text, #_ipad_keyboard_modes, #_point_for_ipad_keyboard_mode_key, #_qstr_for_keyboard, #_query_for_keyboard_mode_key, #_query_for_touch_for_keyboard_mode_option, #_query_uia_hide_keyboard_button, #_search_keyplanes_and_enter_char, #_touch_bottom_keyboard_mode_row, #_touch_top_keyboard_mode_row, #_wait_for_keyboard_in_mode, #await_keyboard, #dismiss_ipad_keyboard, #docked_keyboard_visible?, #done, #ensure_docked_keyboard, #ensure_split_keyboard, #ensure_undocked_keyboard, #ipad_keyboard_mode, #keyboard_enter_char, #keyboard_enter_text, #keyboard_visible?, #split_keyboard_visible?, #tap_keyboard_action_key, #uia_keyboard_visible?, #uia_wait_for_keyboard, #undocked_keyboard_visible?, #wait_for_keyboard

Methods included from TestsHelpers

#check_element_does_not_exist, #check_element_exists, #check_view_with_mark_exists, #classes, #each_cell, #each_cell_and_back, #element_does_not_exist, #element_exists, #navigation_path, #query_map, #view_with_mark_exists

Methods included from WaitHelpers

#handle_error_with_options, #screenshot_and_retry, #touch_transition, #until_element_does_not_exist, #until_element_exists, #wait_error, #wait_for, #wait_for_condition, #wait_for_elements_do_not_exist, #wait_for_elements_exist, #wait_for_no_network_indicator, #wait_for_none_animating, #wait_for_transition, #wait_poll, #when_element_exists

Instance Method Details

#assert_home_direction(expected) ⇒ Object



48
49
50
51
52
# File 'lib/calabash-cucumber/operations.rb', line 48

def assert_home_direction(expected)
  unless expected.to_sym == home_direction
    screenshot_and_raise "Expected home button to have direction #{expected} but had #{home_direction}"
  end
end

#await_page(clz, *args) ⇒ Object



40
41
42
# File 'lib/calabash-cucumber/operations.rb', line 40

def await_page(clz,*args)
  clz.new(self,*args).await
end

#clear_text(uiquery) ⇒ Object

sets the text value of the views matched by uiquery to '' (the empty string)

using this sparingly and with caution

it is recommended that you instead do some combination of the following

  • use queries and touches to replicate with the user would

    • for text fields, implement a clear text button and touch it

    • for text views, use touches to reveal text editing popup

    see github.com/calabash/calabash-ios/issues/151

https://github.com/calabash/calabash-ios/wiki/03.5-Calabash-iOS-Ruby-API

raises an error if the uiquery finds no matching queries or finds a single view that does not respond to the objc selector ‘setText’

IMPORTANT calling:

> clear_text("view")

will clear the text on all visible views that respond to ‘setText’



147
148
149
150
151
152
# File 'lib/calabash-cucumber/operations.rb', line 147

def clear_text(uiquery)
  views_modified = map(uiquery, :setText, '')
  msg = "query '#{uiquery}' returned no matching views that respond to 'setText'"
  assert_map_results(views_modified, msg)
  views_modified
end

#home_directionObject



44
45
46
# File 'lib/calabash-cucumber/operations.rb', line 44

def home_direction
  status_bar_orientation.to_sym
end

#html(q) ⇒ Object



80
81
82
# File 'lib/calabash-cucumber/operations.rb', line 80

def html(q)
  query(q).map { |e| e['html'] }
end

#identifier(uiquery) ⇒ Object



58
59
60
# File 'lib/calabash-cucumber/operations.rb', line 58

def identifier(uiquery)
  query(uiquery, :accessibilityIdentifier)
end

#label(uiquery) ⇒ Object



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

def label(uiquery)
  query(uiquery, :accessibilityLabel)
end

#page(clz, *args) ⇒ Object



36
37
38
# File 'lib/calabash-cucumber/operations.rb', line 36

def page(clz,*args)
  clz.new(self,*args)
end

#set_text(uiquery, txt) ⇒ Object

Deprecated.

since 0.9.145

sets the text value of the views matched by uiquery to txt

we have stopped testing this method. you have been warned.

  • to enter text using the native keyboard use ‘keyboard_enter_text’

  • to delete text use ‘keyboard_enter_text(’Delete’)“

  • to clear a text field or text view:

    • RECOMMENDED: use queries and touches to replicate what the user would do

    • use ‘clear_text’

https://github.com/calabash/calabash-ios/wiki/03.5-Calabash-iOS-Ruby-API

raises an error if the uiquery finds no matching queries or finds a view that does not respond to the objc selector ‘setText’



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/calabash-cucumber/operations.rb', line 102

def set_text(uiquery, txt)
  msgs = ["'set_text' is deprecated and its behavior is now unpredictable",
          "* to enter text using the native keyboard use 'keyboard_enter_text'",
          "* to delete text use 'keyboard_enter_text('Delete')",
          '* to clear a text field or text view:',
          '  - RECOMMENDED: use queries and touches to replicate what the user would do',
          '    * for text fields, implement a clear text button and touch it',
          '    * for text views, use touches to reveal text editing popup',
          '    see https://github.com/calabash/calabash-ios/issues/151',
          "  - use 'clear_text'",
          'https://github.com/calabash/calabash-ios/wiki/03.5-Calabash-iOS-Ruby-API']
  msg = msgs.join("\n")
  _deprecated('0.9.145', msg, :warn)

  text_fields_modified = map(uiquery, :setText, txt)

  msg = "query '#{uiquery}' returned no matching views that respond to 'setText'"
  assert_map_results(text_fields_modified, msg)
  text_fields_modified
end

#set_user_pref(key, val) ⇒ Object



155
156
157
158
159
160
161
162
163
164
# File 'lib/calabash-cucumber/operations.rb', line 155

def set_user_pref(key, val)
  res = http({:method => :post, :path => 'userprefs'},
             {:key=> key, :value => val})
  res = JSON.parse(res)
  if res['outcome'] != 'SUCCESS'
    screenshot_and_raise "set_user_pref #{key} = #{val} failed because: #{res['reason']}\n#{res['details']}"
  end

  res['results']
end

#simple_touch(label, *args) ⇒ Object



62
63
64
# File 'lib/calabash-cucumber/operations.rb', line 62

def simple_touch(label, *args)
  touch("view marked:'#{label}'", *args)
end

#tap(hash_or_string, *args) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/calabash-cucumber/operations.rb', line 66

def tap(hash_or_string, *args)
  if hash_or_string.is_a?(String)
    tap_mark(hash_or_string, *args)
  elsif hash_or_string.respond_to?(:[])
    wait_tap(hash_or_string[:query], hash_or_string)
  else
    raise(ArgumentError, "first parameter to tap must be a string or a hash. Was: #{hash_or_string.class}, #{hash_or_string}")
  end
end

#tap_mark(label, *args) ⇒ Object



76
77
78
# File 'lib/calabash-cucumber/operations.rb', line 76

def tap_mark(label, *args)
  simple_touch(label, *args)
end

#user_pref(key) ⇒ Object



166
167
168
169
170
171
172
173
174
175
# File 'lib/calabash-cucumber/operations.rb', line 166

def user_pref(key)
  res = http({:method => :get, :raw => true, :path => 'userprefs'},
             {:key=> key})
  res = JSON.parse(res)
  if res['outcome'] != 'SUCCESS'
    screenshot_and_raise "get user_pref #{key} failed because: #{res['reason']}\n#{res['details']}"
  end

  res['results'].first
end