使用Espresso时在SearchView上提交测试文本 [英] Test text submit on SearchView when using Espresso
本文介绍了使用Espresso时在SearchView上提交测试文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 androidTest 中向SearchView
提交一些文本?
How can I submit some text to SearchView
in androidTest?
onView(withId(R.id.search_src_text)).perform(typeText("text"))
对我不起作用-应用程序在此行崩溃
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:层次结构中没有视图 找到匹配项:ID:com.example.test:id/search_src_text
androidx.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id: com.example.test:id/search_src_text
推荐答案
您可以使用Resource#getSystem获取视图
you can use Resource#getSystem to get the View
Resources.getSystem().getIdentifier("search_src_text",
"id", "android")
onView(withId(Resources.getSystem().getIdentifier("search_src_text",
"id", "android"))).perform(clearText(),typeText("enter the text"))
.perform(pressKey(KeyEvent.KEYCODE_ENTER))
这篇关于使用Espresso时在SearchView上提交测试文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文