Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 839
Rizki Januar Koeswiyono Avatar asked Aug 06 '16 14:08

Rizki Januar Koeswiyono


People also ask

What is record espresso test in Android Studio?

Espresso Test Recorder is a new feature released in Android Studio 2.2 Preview 3 that makes it easy to generate automated UI tests by recording your own interactions on a device so you don't have to actually write any test code.

What is Expresso in mobile testing?

Espresso created by Google is a native framework for Android automated testing. The tool is a part of the Android SDK and is easy to use for native mobile development. Thanks to Espresso, you can create tests that are close to the Android app's logic.


2 Answers

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.

like image 150
splatte Avatar answered Oct 17 '22 09:10

splatte


  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());

like image 29
Dmitriy Avatar answered Oct 17 '22 11:10

Dmitriy