Test text submit on SearchView when using Espresso

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 03:22:52

问题


How can I submit some text to SearchView in androidTest?

onView(withId(R.id.search_src_text)).perform(typeText("text")) doesn't work for me - app crashes at this line

@Test
fun testSearchViewTextSubmit() {
    ActivityScenario.launch(MainActivity::class.java)

    onView(withId(R.id.search_action)).perform(click()) // ok 

    onView(withId(R.id.search_src_text)).perform(typeText("text")) // failed
}

androidx.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id: com.example.test:id/search_src_text


回答1:


@LorenzoCamaione answer was success when I tried with my application.

        onView(withId(android.support.design.R.id.search_src_text)).perform(typeText("example"), pressKey(
        KeyEvent.KEYCODE_ENTER));

Lorenzo answer in other SO thread



来源:https://stackoverflow.com/questions/58228015/test-text-submit-on-searchview-when-using-espresso

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!