Pranit Pranit - 10 months ago 72
Android Question

Automating number picker in android using espresso

How to automate number picker using espresso. I want to set specific time in the timePicker using espresso.


To match a View by its class name you can simply use:


Once you have the ViewInteraction object you can set a value on it defining and using a ViewAction as following:

public static ViewAction setTime(int hour, int minute) {
        return new ViewAction() {
            public void perform(UiController uiController, View view) {
                TimePicker tp = (TimePicker) view;
            public String getDescription() {
                return "Set the passed time into the TimePicker";
            public Matcher<View> getConstraints() {
                return ViewMatchers.isAssignableFrom(TimePicker.class);