Sendi
Sendi

Reputation: 53

How to presskey editor action on Espresso

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

onView(withId(R.id.edToNumber)).perform(typeText("MDO158"),ViewActions.pressKey(KeyEvent.ACTION_UP), closeSoftKeyboard())

Upvotes: 4

Views: 3140

Answers (2)

karan
karan

Reputation: 8853

You can use below code

onView(withId(R.id.edToNumber))
        .perform(typeText("some"), pressImeActionButton());

Upvotes: 2

I am a Student
I am a Student

Reputation: 1590

To click the ActionDone button from the keyboard of a Specific EditText, you could done by using this code:

onView(withId(R.id.edToNumber)).perform(typeText("MDO158");
onView(withId(R.id.edToNumber)).perform(pressImeActionButton());

Note:

pressImeActionButton() not specifically used for click the ActionDone button from the keyboard, it click whatever ActionButton that the keyboard consist such as ActionDone, ActionSearch, ActionNext, etc.

Optionally, you can close the keyboard of a Specific EditText without click the ActionDone button by using this code:

onView(withId(R.id.edToNumber)).perform(typeText("MDO158");
onView(withId(R.id.edToNumber)).perform(closeSoftKeyboard());

Upvotes: 11

Related Questions