OnEditorActionListener not working when testing

Issue

I’m using OnEditorActionListener on a EditText

scoreboardNameEdit.setOnEditorActionListener(new TextView.OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        ...
    }
});

Everything worked well during development and when testing manually. Now i want to test it with Android Espresso

onView(withId(tv_id)).perform(typeText(to_type)).perform(closeSoftKeyboard());

and the OnEditorActionListener does not get called

Is this a common problem with Android Espresso?

Solution

closeSoftKeyboard(): sounds to me like that is only hiding the keyboard. Try to use one of the different methods in ViewActions.

From the docs:

  • ViewActions#closeSoftKeyboard() : Returns an action that closes soft keyboard.

  • ViewActions#pressImeActionButton() : Returns an action that presses the current action button (next, done, search, etc) on the IME (Input Method Editor).

I would place my bet on pressImeActionButton() (untested offcourse)

Answered By – Entreco

Leave a Comment