I am using Espresso to test an app with several AutoCompleteTextViews. For one particular test, the autocomplete popup appears, but I want to just ignore it and move to the next TextView. How can I do this? My ideas are to either simulate a "Back" press or simulate a tap in the popup.
I am attempting the following to click on the autocomplete popup:
Now the problem is that in some cases, the text entered doesn't have any autocomplete matches so no popup appears. How do I conditionally perform the click depending on whether or not a view is matched?
Then I call UiDevice.pressEnter() to advance to the next TextView.
The problem encountered is that this doesn't work as expected out of the box. I also added a View.OnKeyListener to each AutoCompleteTextView to handle the Enter key event. For now I add a listener to each view and explicitly state which view requests focus on an Enter key event.
This isn't ideal. Eventually I plan to generalize this, possibly with a custom component which inherits from AutoCompleteTextView which handles the Enter key as I expect. It will send focus to the "next" view.
Asked in February 2016Viewed 1,513 timesVoted 9Answered 1 times