Date picker issue

1,135 views
Skip to first unread message

Stan

unread,
Oct 1, 2012, 4:28:07 PM10/1/12
to calaba...@googlegroups.com

I'm using one of the user contributed step definitions for the date picker (https://gist.github.com/e952bf49099279e3c212). Running into a problem where when it scrolls up or down, it'll quickly jump back to its original selection.

 

This happens through the console also. With the date picker open on the simulator, I enter on the console: scroll("scrollView index:0","up"). I'll get the same behavior where it scrolls up, then jumps back to it's original selection.

 

Is there a workaround for this to set the date without scrolling? I know it sees the date correctly:


irb(main):039:0> query("datePicker","date")

=> ["2012-10-11 02:00:00 +0000"]

 

Would like to pass a statement that'll just update that date/time.


Thanks

Krukow

unread,
Oct 4, 2012, 3:43:22 AM10/4/12
to calaba...@googlegroups.com
Hi Stan,
On Monday, October 1, 2012 10:28:07 PM UTC+2, Stan wrote:
[snip.] 

This happens through the console also. With the date picker open on the simulator, I enter on the console: scroll("scrollView index:0","up"). I'll get the same behavior where it scrolls up, then jumps back to it's original selection.


Isn't that because the scroll command will scroll too much and you end up scrolling into an invalid selection (so validation will pop it back)?

The simples thing you can do is to just use "touch" to touch the text for the date/time you want. E.g. something like

 touch("pickerView scrollView index:0 label text:'05'")

One other simple approach is to do a recording of a touch sequence where you move one of the wheels just a single "nudge". You can then play back the recording on one of the wheels using something like

playback("nudge_down",  :query => "pickerView scrollView index:0")


 

Is there a workaround for this to set the date without scrolling? I know it sees the date correctly:


irb(main):039:0> query("datePicker","date")

=> ["2012-10-11 02:00:00 +0000"]

[snip.]

Yes - you can try the above methods I outlined.

- Karl 

Joshua Moody

unread,
Nov 18, 2012, 6:10:26 PM11/18/12
to calaba...@googlegroups.com
i put some working into my date picker steps referenced above. 

find the new gist here:  https://gist.github.com/4103369

i updated the wiki.

Joshua Moody

unread,
Nov 18, 2012, 6:17:54 PM11/18/12
to calaba...@googlegroups.com

I'm using one of the user contributed step definitions for the date picker (https://gist.github.com/e952bf49099279e3c212). Running into a problem where when it scrolls up or down, it'll quickly jump back to its original selection.


This happens through the console also. With the date picker open on the simulator, I enter on the console: scroll("scrollView index:0","up"). I'll get the same behavior where it scrolls up, then jumps back to it's original selection.


this can happen if you are trying to move the date picker past a minimum or maximum date.  the new steps attempt to handle this. 
 

Is there a workaround for this to set the date without scrolling? I know it sees the date correctly:


irb(main):039:0> query("datePicker","date")

=> ["2012-10-11 02:00:00 +0000"]

 

Would like to pass a statement that'll just update that date/time.


have a look at the  new steps.   they provide 2 ways to manipulate the picker:

1. AUTOMATIC <== setting the date directly using a UIDatePicker category method
2. MANUAL <== setting the date by manipulating the picker wheels

be sure to read the long (sorry - it is really long) comment at the beginning of the date_picker_steps.rb and be aware that the gist contains 2 files.

Trevor Harmon

unread,
Nov 19, 2012, 3:38:58 PM11/19/12
to calaba...@googlegroups.com
Hmm, is all of that code really necessary? How about:

def select_date(date_string)
date = Date.parse(date_string)

# Go in order of year, month, day so that the expected day range is available
query("view:'_UIDatePickerView'", [{:selectRow => date.year - 1}, {:inComponent => 2}, {:animated => 0}])
query("view:'_UIDatePickerView'", [{:selectRow => date.month - 1}, {:inComponent => 0}, {:animated => 0}])
query("view:'_UIDatePickerView'", [{:selectRow => date.day - 1}, {:inComponent => 1}, {:animated => 0}])
end

Granted, this doesn't support time mode, but these few lines are all I've needed for my UIDatePicker steps so far.

Trevor

Joshua Moody

unread,
Nov 20, 2012, 4:41:06 AM11/20/12
to calaba...@googlegroups.com

Hmm, is all of that code really necessary? How about:

 def select_date(date_string)
   date = Date.parse(date_string)

   # Go in order of year, month, day so that the expected day range is available
   query("view:'_UIDatePickerView'", [{:selectRow => date.year - 1},  {:inComponent => 2}, {:animated => 0}])
   query("view:'_UIDatePickerView'", [{:selectRow => date.month - 1}, {:inComponent => 0}, {:animated => 0}])
   query("view:'_UIDatePickerView'", [{:selectRow => date.day - 1},   {:inComponent => 1}, {:animated => 0}])
 end

Granted, this doesn't support time mode, but these few lines are all I've needed for my UIDatePicker steps so far.

yeah, i am not happy with how much code there is.   but i have clients writing tests is both 12h and 24h time formats, sometimes in the same scenario and the tests have to pass on devices in US and EU locales.    the automatic date-setting approach where i use a category on the date picker is actually very few lines of code.  supporting manual scrolling takes up the bulk of the file. 

it looks like your approach could be used to trim things down and remove the need for the category (i completely missed the selectRow:inComponent:animated) - cool!  and thanks!

i am not an experienced ruby programmer and i have even less experience with cucumber.  i am really excited to get feedback like this.   i have been wondering if there is a way we (the calabash-ios community) can share our steps for interacting with complex ui objects like the date picker.   anyone have any thoughts?   i have a bunch of steps that want to contribute and get feedback on.   



Trevor Harmon

unread,
Nov 20, 2012, 9:38:49 PM11/20/12
to calaba...@googlegroups.com
On Nov 20, 2012, at 1:41 AM, Joshua Moody <joshua...@gmail.com> wrote:

> i have been wondering if there is a way we (the calabash-ios community) can share our steps for interacting with complex ui objects like the date picker. anyone have any thoughts? i have a bunch of steps that want to contribute and get feedback on.

I sometimes write generic step definitions and API functions that could belong in Calabash. I collect these in:

features/step_definitions/calabash_steps.rb
features/support/calabash_support.rb

When I have some time, I plan to post my collection to this list for feedback, and if there is interest, submit a pull request to have them incorporated into the official Calabash distribution.

Trevor

Александр Хозя

unread,
Nov 25, 2012, 8:23:08 AM11/25/12
to calaba...@googlegroups.com
That would be very cool! Guys, looking forward to your steps, because I have almost no experience with Ruby and Cucumber :)

engr.a...@gmail.com

unread,
Aug 5, 2014, 6:59:54 AM8/5/14
to calaba...@googlegroups.com
Hi friends !
I am using a simple code for date picker for my Calabash-iOS automation. Whenever I set the today's or some past date to select, it is failed. I hope someone would have the idea about it.

Here is my code and error messages:

Then(/^I set Reminder Date "(.*?)" Time "(.*?)"$/) do |date10, time10|

    target_time = Time.parse(time10)

    target_date = Date.parse(date10)

    current_time = date_time_from_picker()

    current_date = date_time_from_picker()

    date_time = DateTime.new(target_date.year,

                             target_date.mon,

                             target_date.day,

                             target_time.hour,

                             target_time.min,

                             0,

                             target_time.gmt_offset)                             

    picker_set_date_time date_time

    sleep(3)

end

Then I set Reminder Date "05/08/2014" Time "5:24"

If the set date is todays date or a past date, this fails and if it is some future date, it passes. 
If some friends knows its solution, please suggest. Thanks
Reply all
Reply to author
Forward
0 new messages