How to press "search button" on softkeyboard emulator in Espresso Test Android Studio

How can I press the "search button" on the soft keyboard emulator in Espresso Test Android Studio? It's on the bottom right.

screenshot of emulator

Upvotes: 14

Views: 5319

Answers (2)

Dmitriy
Dmitriy

Reputation: 517

  1. In the layout file set property for EditText android:imeOptions="actionSearch";
  2. Then use the previous answer:

    onView(withId(R.id.search_box)) .perform(pressImeActionButton());

Upvotes: 1

splatte
splatte

Reputation: 2078

Use the pressImeActionButton() ViewAction documented here: https://developer.android.com/reference/android/support/test/espresso/action/ViewActions.html#pressImeActionButton()

onView(withId(R.id.search_box))
    .perform(pressImeActionButton());

In addition, you can use hasImeAction (int imeAction) documented here https://developer.android.com/reference/android/support/test/espresso/matcher/ViewMatchers.html#hasImeAction(int) to check whether the expected IME action is displayed.

Upvotes: 27

Related Questions