3

I have an autocomplete textview and I am setting an Adapter view on it to show the list of suggestions. While testing on espresso, I want to select an item position from list of suggestions but, it does not identify the auto complete text view adapter on espresso.

I tried this answer from Stack overflow: DropDown value selection using espresso android with dynamic element id's

But, this did not work for me. Any help on this would be great. Thanks.

Community
  • 1
  • 1
shrutika
  • 41
  • 1
  • 7

2 Answers2

3

or you can try instead onData. Because onData not working for me

 onView(withText("Your field name"))
.inRoot(withDecorView(not(is(getActivity().getWindow().getDecorView()))))
            .perform(click());
0

I run into the same problem and this is how i did it:

onView(withId(R.id.sp_country/*auto complete textview*/)).perform(click());
onData(allOf(is(instanceOf(String.class)), is(COUNTRY/*selected value autocomplete collection*/)))
                .inRoot(RootMatchers.withDecorView(not(is(activityActivityTestRule
                        .getActivity().getWindow().getDecorView()))))
                .perform(click());
elvisrusu
  • 378
  • 5
  • 18