问题
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