2014-01-16 2 views

답변

1

같은 내가 몇 가지 조사 후 솔루션을 제작합니다. 이 코드는 방탄이 아니지만 잘 작동합니다. 나는 누군가가 이것으로부터 도움을 얻을 것이라고 생각한다. 누구든지 이것을 향상시키는 방법을 알고 있다면. 여기에 추가하십시오. Chathura 언급

I 추가 단계 정의에

..

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 
1

그 요지는 매우 오래된 것이다.

이제 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" 
+0

감사 여호수아 .. 나는 호리병박 0.14.x에 대한 구식 링크 –

+0

업데이트 대답을 제거 – jmoody