android - How to set time to MaterialDateTimePicker with Espresso -


im trying create simple ui test using espresso set date newly created item.

project using https://github.com/wdullaer/materialdatetimepicker, shows dialog fragment complex ui , nothing hold on to.

i create custom viewaction set date or time similar pickeractions espresso.

any suggestions how it?

in end i've created viewaction able set time too, messy, have know classname of view in dialog, have match matcher.

  /**      * returns {@link viewaction} sets date on {@link datepicker}.      */     public static viewaction setdate(final int year, final int monthofyear, final int dayofmonth) {          return new viewaction() {              @override             public void perform(uicontroller uicontroller, view view) {                 final daypickerview daypickerview = (daypickerview) view;                  try {                     field f = null; //nosuchfieldexception                     f = daypickerview.class.getdeclaredfield("mcontroller");                     f.setaccessible(true);                     datepickercontroller controller = (datepickercontroller) f.get(daypickerview); //illegalaccessexception                     controller.ondayofmonthselected(year, monthofyear, dayofmonth);                 } catch (nosuchfieldexception e) {                     e.printstacktrace();                 } catch (illegalaccessexception e) {                     e.printstacktrace();                 }             }              @override             public string getdescription() {                 return "set date";             }              @suppresswarnings("unchecked")             @override             public matcher<view> getconstraints() {                 return allof(isassignablefrom(daypickerview.class), isdisplayed());             }         };      }      /**      * returns {@link viewaction} sets time on {@link timepicker}.      */     public static viewaction settime(final int hours, final int minutes) {          return new viewaction() {              @override             public void perform(uicontroller uicontroller, view view) {                 final radialpickerlayout timepicker = (radialpickerlayout) view;                  timepicker.settime(new timepoint(hours, minutes, 0));             }              @override             public string getdescription() {                 return "set time";             }              @suppresswarnings("unchecked")             @override             public matcher<view> getconstraints() {                 return allof(isassignablefrom(radialpickerlayout.class), isdisplayed());             }         };      } 

and usage:

onview(isassignablefrom(daypickerview.class)).perform(materialpickeractions.setdate(calendar.get(calendar.year), calendar.get(calendar.month), calendar.get(calendar.day_of_month)));  onview(isassignablefrom(radialpickerlayout.class)).perform(materialpickeractions.settime(calendar.get(calendar.hour_of_day), calendar.get(calendar.minute))); 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -