0

I have a Autocomplete box, whit a costum "CityAdapter", how can i access the Button/ImageView using expresso test? I filter the costum adapter by cityName, so i can find the citys by name.

 onView(withId(R.id.autoCompleteCities))
                .perform(typeText(""), closeSoftKeyboard());
         Activity mActivity=mActivityTestRule.getActivity();

onData(instanceOf(CityAdapter.class))
                    .inAdapterView(withId(R.id.autoCompleteCities))
                    .atPosition(0)
                    .onChildView(withId(R.id.tvFavourite))
                    .perform(click());

Here is a example:enter image description here

João Marques
  • 121
  • 1
  • 1
  • 14

1 Answers1

0

You can do the following:

    onView(withId(R.id.autoCompleteCities))
            .perform(typeText("E"));

    onData(instanceOf(City.class))
            .inRoot(RootMatchers.isPlatformPopup())
            .atPosition(0)
            .onChildView(withId(R.id.tvFavourite))
            .perform(click());
  • onView(~).perform(~) is to show the auto complete listview in the view-port.
  • onData(instanceOf(City.class)) This will find the view with the object same as that of the mentioned class (here City.class).
  • inRoot(RootMatchers.isPlatformPopup()) The dropdown menu is on another window than the default window your activity runs in. So we have to specify that we want to search that window.
  • atPosition(0) Selects the item at the specified position in the array-list or list-view.
  • onChildView(withId(R.id.tvFavourite)) Selects the child view with the specified ID (here image-view).

~ Reference https://stackoverflow.com/a/45368345/8885981

Manav Jain
  • 1,406
  • 1
  • 8
  • 5