Module: Calabash::Cucumber::DatePicker

Includes:
Core
Included in:
Operations
Defined in:
lib/calabash-cucumber/date_picker.rb

Overview

A collection of methods for interacting with UIDatePicker

Instance Method Summary collapse

Methods included from Core

#await_page, #backdoor, #calabash_exit, #calabash_info, #calabash_warn, #clear_text, #client_version, #console_attach, #deprecated, #device_agent, #dismiss_ipad_keyboard, #double_tap, #flash, #flick, #html, #identifier, #keyboard_enter_char, #keyboard_enter_text, #label, #location_for_place, #page, #pan, #pan_coordinates, #pinch, #query, #rotate, #rotate_home_button_to, #scroll, #scroll_to_cell, #scroll_to_collection_view_item, #scroll_to_collection_view_item_with_mark, #scroll_to_mark, #scroll_to_row, #scroll_to_row_with_mark, #send_app_to_background, #server_log_level, #server_version, #set_location, #set_server_log_level, #set_text, #set_user_pref, #shake, #slider_set_value, #start_test_server_in_background, #swipe, #tap_keyboard_action_key, #tap_keyboard_delete_key, #tap_mark, #tap_point, #touch, #touch_hold, #two_finger_tap, #user_pref

Methods included from KeyboardHelpers

#docked_keyboard_visible?, #keyboard_visible?, #lookup_key_name, #split_keyboard_visible?, #undocked_keyboard_visible?, #wait_for_keyboard, #wait_for_no_keyboard

Methods included from StatusBarHelpers

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

Methods included from UIA

#uia, #uia_call, #uia_call_windows, #uia_keyboard_visible?, #uia_names, #uia_orientation, #uia_query, #uia_query_windows, #uia_rotate, #uia_rotate_home_button_to, #uia_set_responder_value, #uia_wait_for_keyboard

Methods included from FailureHelpers

#fail, #screenshot, #screenshot_and_raise, #screenshot_embed

Methods included from QueryHelpers

#escape_backslashes, #escape_newlines, #escape_quotes, #escape_string

Methods included from EnvironmentHelpers

#default_device, #device_family_iphone?, #ios10?, #ios5?, #ios6?, #ios7?, #ios8?, #ios9?, #ios_version, #ipad?, #ipad_pro?, #iphone?, #iphone_35in?, #iphone_4in?, #iphone_6?, #iphone_6_plus?, #iphone_app_emulated_on_ipad?, #ipod?, #screen_dimensions, #simulator?, #uia_available?, #uia_not_available?, #xamarin_test_cloud?

Instance Method Details

#countdown_mode?(picker_id = nil) ⇒ Boolean

Is the date picker in countdown mode?

Parameters:

  • picker_id (String) (defaults to: nil)

    The accessibility label or id of the picker you are looking for. If nil, then the first UIDatePicker that is found will be queried.

Returns:

  • (Boolean)

    true if the picker is in countdown mode

Raises:

  • (RuntimeError)

    if no picker can be found

See Also:



115
116
117
# File 'lib/calabash-cucumber/date_picker.rb', line 115

def countdown_mode?(picker_id=nil)
  date_picker_mode(picker_id) == UI_DATE_PICKER_MODE_COUNT_DOWN_TIMER
end

#date_and_time_mode?(picker_id = nil) ⇒ Boolean

Is the date picker in date and time mode?

Parameters:

  • picker_id (String) (defaults to: nil)

    The accessibility label or id of the picker you are looking for. If nil, then the first UIDatePicker that is found will be queried.

Returns:

  • (Boolean)

    true if the picker is in date and time mode

Raises:

  • (RuntimeError)

    if no picker can be found

See Also:



99
100
101
# File 'lib/calabash-cucumber/date_picker.rb', line 99

def date_and_time_mode?(picker_id=nil)
  date_picker_mode(picker_id) == UI_DATE_PICKER_MODE_DATE_AND_TIME
end

#date_mode?(picker_id = nil) ⇒ Boolean

Is the date picker in date mode?

Parameters:

  • picker_id (String) (defaults to: nil)

    The accessibility label or id of the picker you are looking for. If nil, then the first UIDatePicker that is found will be queried.

Returns:

  • (Boolean)

    true if the picker is in date mode

Raises:

  • (RuntimeError)

    if no picker can be found

See Also:



83
84
85
# File 'lib/calabash-cucumber/date_picker.rb', line 83

def date_mode?(picker_id=nil)
  date_picker_mode(picker_id) == UI_DATE_PICKER_MODE_DATE
end

#date_time_from_picker(picker_id = nil) ⇒ DateTime

Returns the date and time from the picker.

Parameters:

  • picker_id (String) (defaults to: nil)

    The accessibility label or id of the picker you are looking for. If nil, then the first UIDatePicker that is found will be queried.

Returns:

  • (DateTime)

    the date on the picker

Raises:

  • (RuntimeError)

    if the picker is in countdown mode

  • (RuntimeError)

    if the picker cannot be found



208
209
210
211
212
213
214
215
216
217
218
# File 'lib/calabash-cucumber/date_picker.rb', line 208

def date_time_from_picker (picker_id=nil)
  if countdown_mode? picker_id
    screenshot_and_raise 'method is not available for pickers that are not in date or date time mode'
  end
  query_str = query_string_for_picker picker_id
  res = query(query_str, :date)
  if res.empty?
    screenshot_and_raise "should be able to get date from picker with query '#{query_str}'"
  end
  DateTime.parse(res.first)
end

#maximum_date_time_from_picker(picker_id = nil) ⇒ DateTime

Note:

From the Apple docs: The property is an NSDate object or nil (the default).

The maximum date for a picker. If there is no maximum date, this method returns nil.

Parameters:

  • picker_id (String) (defaults to: nil)

    The accessibility label or id of the picker you are looking for. If nil, then the first UIDatePicker that is found will be queried.

Returns:

  • (DateTime)

    the maximum date on the picker or nil if no maximum exists

Raises:

  • (RuntimeError)

    if the picker is in countdown mode

  • (RuntimeError)

    if the picker cannot be found



158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/calabash-cucumber/date_picker.rb', line 158

def maximum_date_time_from_picker (picker_id = nil)
  if countdown_mode? picker_id
    screenshot_and_raise 'method is not available for pickers that are not in date or date time mode'
  end

  query_str = should_see_date_picker picker_id
  res = query(query_str, :maximumDate)
  if res.empty?
    screenshot_and_raise "should be able to get max date from picker with query '#{query_str}'"
  end
  return nil if res.first.nil?
  DateTime.parse(res.first)
end

#minimum_date_time_from_picker(picker_id = nil) ⇒ DateTime

Note:

From the Apple docs: The property is an NSDate object or nil (the default).

The minimum date for a picker. If there is no minimum date, this method returns nil.

Parameters:

  • picker_id (String) (defaults to: nil)

    The accessibility label or id of the picker you are looking for. If nil, then the first UIDatePicker that is found will be queried.

Returns:

  • (DateTime)

    the minimum date on the picker or nil if no minimum exists

Raises:

  • (RuntimeError)

    if the picker is in countdown mode

  • (RuntimeError)

    if the picker cannot be found



186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/calabash-cucumber/date_picker.rb', line 186

def minimum_date_time_from_picker (picker_id = nil)
  if countdown_mode? picker_id
    screenshot_and_raise 'method is not available for pickers that are not in date or date time mode'
  end

  query_str = should_see_date_picker picker_id
  res = query(query_str, :minimumDate)
  if res.empty?
    screenshot_and_raise "should be able to get min date from picker with query '#{query_str}'"
  end
  return nil if res.first.nil?
  DateTime.parse(res.first)
end

#picker_set_date_time(target_dt, options = {:animate => true, :picker_id => nil, :notify_targets => true}) ⇒ Object

TODO:

replace args_for_change_date_on_picker with hash table merge

Note:

When :notify_targets => true this operation iterates through the target/action pairs on the objc UIDatePicker instance and calls

Sets the date and time on picker.

performSelector:<action> object:<target>. This has the effect of generating UIEvents.

Parameters:

  • target_dt (DateTime)

    the date and time you want to change to

  • options (Hash) (defaults to: {:animate => true, :picker_id => nil, :notify_targets => true})

    controls the behavior of this method

Options Hash (options):

  • :animate (Boolean) — default: true

    animate the date change

  • :picker_id (String) — default: nil

    The accessibility id or label of the date picker you are looking for. If nil, the first UIDatePicker that is found will have the date and time applied.

  • :notify_target (Boolean) — default: true

    If true, all the date picker's target/action pairs will be called. This is necessary to generate UIEvents. If false, no UIEvents will be generated and it is likely that your UI will not update correctly.

Raises:

  • (RuntimeError)

    if no date picker can be found

  • (RuntimeError)

    if the target date is greater than the picker's maximum date

  • (RuntimeError)

    if the target date is less than the picker's minimum date

  • (RuntimeError)

    if the target date is not a DateTime instance



265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/calabash-cucumber/date_picker.rb', line 265

def picker_set_date_time (target_dt, options = {:animate => true,
                                                :picker_id => nil,
                                                :notify_targets => true})
  unless target_dt.is_a?(DateTime)
    raise "target_dt must be a DateTime but found '#{target_dt.class}'"
  end

  picker_id = options == nil ? nil : options[:picker_id]

  if time_mode?(picker_id) == UI_DATE_PICKER_MODE_COUNT_DOWN_TIMER
    pending('picker is in count down mode which is not yet supported')
  end

  target_str = target_dt.strftime(RUBY_DATE_AND_TIME_FMT).squeeze(' ').strip
  fmt_str = OBJC_DATE_AND_TIME_FMT

  args = args_for_change_date_on_picker options
  query_str = query_string_for_picker picker_id

  views_touched = Map.map(query_str, :changeDatePickerDate, target_str,
                          fmt_str, *args)
  msg = "could not change date on picker to '#{target_dt}' using query '#{query_str}' with options '#{options}'"
  Map.assert_map_results(views_touched,msg)
  views_touched
end

#should_see_date_picker(picker_id = nil) ⇒ Object

Asserts that a date picker is visible.

Parameters:

  • picker_id (String) (defaults to: nil)

    The accessibility label or id of the picker you are looking for. If nil, any visible date picker will satisfy the assertion.

Raises:

  • (RuntimeError)

    if a matching date picker is not visible



136
137
138
139
140
141
142
# File 'lib/calabash-cucumber/date_picker.rb', line 136

def should_see_date_picker (picker_id=nil)
  query_str = query_string_for_picker picker_id
  if query(query_str).empty?
    screenshot_and_raise "should see picker with query '#{query_str}'"
  end
  query_str
end

#time_mode?(picker_id = nil) ⇒ Boolean

Is the date picker in time mode?

Parameters:

  • picker_id (String) (defaults to: nil)

    The accessibility label or id of the picker you are looking for. If nil, then the first UIDatePicker that is found will be queried.

Returns:

  • (Boolean)

    true if the picker is in time mode

Raises:

  • (RuntimeError)

    if no picker can be found

See Also:



67
68
69
# File 'lib/calabash-cucumber/date_picker.rb', line 67

def time_mode?(picker_id=nil)
  date_picker_mode(picker_id) == UI_DATE_PICKER_MODE_TIME
end