如何使用android espresso按默认软键?

时间:2017-12-30 19:00:15

标签: android android-softkeyboard android-espresso searchview

当用户在填写SearchView后按下默认软键按钮时,我需要触发搜索。

如何模拟用户按默认软键?

更新 根据需要,我的代码。

SearchText的xml定义:

    <android.support.v7.widget.SearchView
        android:id="@+id/search_box"
        style="@style/AppTheme.SearchBox"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:scrollbars="none"
        android:soundEffectsEnabled="true" />

代码:

onView(withId(R.id.search_box))
            .perform(typeSearchViewText("whatever query"),pressImeActionButton())

注意:typeSearchViewText是我对typeText

SearchViews的实施

1 个答案:

答案 0 :(得分:0)

您可以使用espresso viewaction方法pressImeActionButton()