如何在Espresso Test Android Studio中的软键盘模拟器上按"搜索按钮"

Riz*_*ono 8 android android-espresso

如何在Espresso Test Android Studio中按下软键盘模拟器上的"搜索按钮"?它位于右下方.

模拟器的截图

spl*_*tte 16

使用pressImeActionButton()此处记录的ViewAction:https://developer.android.com/reference/android/support/test/espresso/action/ViewActions.html#pressImeActionButton()

onView(withId(R.id.search_box))
    .perform(pressImeActionButton());
Run Code Online (Sandbox Code Playgroud)

此外,您可以使用hasImeAction (int imeAction)此处记录的https://developer.android.com/reference/android/support/test/espresso/matcher/ViewMatchers.html#hasImeAction(int)来检查是否显示了预期的IME操作.