androidandroid-espressoautocompletetextview

How to test with Espresso if the popup of an AutoCompleteTextView is open or not in my Android activity


I have an AutoCompleteTextView in my Android Activity

In my espresso test, I want to check if the popup with the proposals is opened or closed.

How can I do that?

I have tried many ideas, including:

onData(anything()).inRoot(RootMatchers.isPlatformPopup()).check(doesNotExist());
onData(anything()).inRoot(RootMatchers.isPlatformPopup()).check(matches(isDisplayed()));
onData(anything()).atPosition(0).inRoot(RootMatchers.isPlatformPopup()).check(matches(isDisplayed()));

In these particular cases, the test just fails or goes to an infinite loop

Example:

In my Adapter, I have 2 values: "abc" and "def"

How can I test (within an Espresso test) if the popup is closed?


Solution

  • AutoCompleteTextView is exposing an isPopupShowing() method which tells the info you're looking for.

    You can probably get the view itself in your test somehow, one option might be to use the activityRule itself (activity.findViewById ...).

    Otherwise, there are few stackoverflow posts on how to hack views out of espresso.. (example)