Calabash: выберите дату из UIDatePickerview

В тестировании Calabash Automation на iPhone. Мне нужно выбрать дату из средства выбора даты. Пожалуйста, помогите мне с рубиновым определением шага.

я хочу что-то вроде

Then I scroll datepicker to date "2002-10-22" 

person Chathura Palihakkara    schedule 16.01.2014    source источник


Ответы (2)


Я сделал решение после некоторых исследований. Этот код не является пуленепробиваемым, но он отлично работает для меня. Думаю, кому-то это поможет. если кто знает как улучшить. Пожалуйста, добавьте его сюда.

В определениях шагов я добавляю..

Then /^I scroll datepicker to date "1985-01-01"
# Date Format "1985-01-01"

# make sure date picker is up
should_see_date_picker()
is_picker_in_date_mode()
maxdate = picker_maximum_date_time()
target = Date.parse(target_date)
current = Date.parse(datequery())

if(maxdate<target)
  screenshot_and_raise "Target date'#{target}' is larger than maximum date'#{maxdate}' in date picker"
end

limit = 100
# => set year
  count = 0
  dir = (target.year < current.year) ? "down" : "up"
  until (target.year == Date.parse(datequery()).year) or (count==limit)  do
      date = Date.parse(datequery())
      scroll_date_component(dir, 2, date.year)
#      puts("Inside the loop1 '#{count}'=> '#{date.year}'" )
    count += 1
  end

# => set month
  count = 0
  dir = (target.month < current.month) ? "down" : "up"
  until (target.month == Date.parse(datequery()).month) or (count==limit)  do
      date = Date.parse(datequery())
      scroll_date_component(dir, 0, date.month)
#      puts("Inside the loop2 '#{count}'=> '#{date.month}'" )
    count += 1
  end

# => set day
  count = 0
  dir = (target.day < current.day) ? "down" : "up"
  until (target.day == Date.parse(datequery()).day) or (count==limit)  do
      date = Date.parse(datequery())
      scroll_date_component(dir, 1, date.day)
#      puts("Inside the loop3 '#{count}'=> '#{date.day}'" )
    count += 1
  end

end

#########################################################

# => ##### Date picker helper methods. #####

    def scroll_date_component(direction, column, component)
      if(column==0)
        # => Month scroll needs the month name string
        if (direction.eql? "up")
          month_str = Date::MONTHNAMES[component+1]
          touch("pickerView scrollView index:#{column} label text:'#{month_str}'")
        elsif (direction.eql? "down")
          month_str = Date::MONTHNAMES[component-1]
          touch("pickerView scrollView index:#{column} label text:'#{month_str}'")
        end
      else
        # => Day and year scrolls are numeric 
        if (direction.eql? "up")
          touch("pickerView scrollView index:#{column} label text:'#{component + 1}'")
        elsif (direction.eql? "down")
          touch("pickerView scrollView index:#{column} label text:'#{component - 1}'")
        end
      end
      sleep(0.3)
    end

def datequery()
   return query("datePicker","date").first 
end

def should_see_date_picker ()
  if query("datePicker", :date).empty?
    screenshot_and_raise "Could not find date picker"
  end
end

def is_picker_in_date_mode()
  res = query("datePicker", :datePickerMode)
  screenshot_and_raise "expected to see a date picker" if res.empty?
  screenshot_and_raise "expected to see UIDatePickerModeDate" if res.first!=1
end

def picker_maximum_date_time()
  res = query("datePicker", :maximumDate)
  screenshot_and_raise "expected to see a date picker" if res.empty?
  return DateTime.parse(res.first) if (res.first)
end
person Chathura Palihakkara    schedule 17.01.2014

Суть, упомянутая Чатурой, очень устарела.

Calabash iOS теперь изначально поддерживает взаимодействие с большинством средств выбора даты.

https://github.com/calabash/calabash-ios/blob/develop/calabash-cucumber/features/step_definitions/calabash_steps.rb#L406

Scenario: I should be able to use the predefined steps to change the picker time
    Then I change the date picker time to "10:45"

Scenario: I should be able to use the predefined steps to change the picker date
    Then I change the date picker date to "July 28 2009"

 Scenario: I should be able to use the predefined steps to change the picker date and time
    Then I change the date picker date to "July 28" at "15:23"
person jmoody    schedule 21.01.2014
comment
Спасибо Джошуа .. Я удаляю устаревшую ссылку - person Chathura Palihakkara; 21.01.2014
comment
Обновленный ответ для Calabash 0.14.x - person jmoody; 04.06.2015