How to press editor action on Espresso

Issue

How do you press the Editor Action key on Android softkey using Espresso? I tried:

onView(withId(R.id.test_title)).perform(typeText("Sample Title"), pressKey(KeyEvent.FLAG_EDITOR_ACTION));

But it’s not working.. Any idea?

Solution

“pressKey” expects a KEYCODE, not a FLAG. So pressKey(KeyEvent.FLAG_EDITOR_ACTION) doesn’t really make sense and will definitely not work.

But there is a ViewAction for pressing the editor (IME) action, see the static method: ViewActions#pressImeActionButton()

You can view the Espresso 1.x implementation details here:

https://developer.android.com/reference/android/support/test/espresso/action/ViewActions.html#pressImeActionButton()

Answered By – yogurtearl

Leave a Comment