Reputation: 151
In Xamarin forms for the time picker below
How do I change the time picker value for the xamarin UI test. I can open the time picker but not sure how to change the time. This is a screen shot of the app.Repl() tree for the time picker.
This is my attempt for trying to change the hours.
app.WaitForElement(c => c.Marked("hours"));
app.Tap(c => c.Marked("hours"));
app.EnterText(c => c.Marked("hours"), newHours) // errors can't pull up keyboard
Upvotes: 0
Views: 901
Reputation: 56
I found the easiest way to handle date and time controls was to use the Invoke method to access the backdoors that are exposed in the time/date picker controls.
// invokes a method to input the hour into the picker, time format is 24 hour
app.Query(c => c.Class("RadialTimePickerView").Invoke("setCurrentHour", (int)hour));
// invokes a method to input the minute into the picker
app.Query(c => c.Class("RadialTimePickerView").Invoke("setCurrentMinute", (int)minute));
And the date picker is very similar, but instead of requiring two separate methods, it just uses one.
// invokes a method to input the date into the picker, where month starts from 0
app.Query(c => c.Raw("DatePicker").Invoke("updateDate", (int)year, (int)month - 1, (int)day));
I would recommend using this particular backdoor as it works across a wide variety of android version, as each version of android has a slightly different style of date/time picker.
Upvotes: 1