Issue
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());
Solution
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 theauto complete listview
in theview-port
.onData(instanceOf(City.class))
This will find the view with the object same as that of the mentioned class (hereCity.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 thearray-list
orlist-view
.onChildView(withId(R.id.tvFavourite))
Selects the child view with the specified ID (hereimage-view
).
~ Reference https://stackoverflow.com/a/45368345/8885981
Answered By - Manav Jain
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.