0

如何SearchViewandroidTest中提交一些文本?

onView(withId(R.id.search_src_text)).perform(typeText("text"))对我不起作用 - 应用程序在此行崩溃

@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

4

2 回答 2

0

当我尝试使用我的应用程序时,@LorenzoCamaione 的答案是成功的。

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

Lorenzo 在其他 SO 线程中的回答

于 2019-10-04T08:20:39.567 回答
0

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))
于 2020-01-11T00:34:45.953 回答