Pranit Pranit - 1 year ago 165
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.

Answer Source

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download