测试我们在AppBar中使用Android原生搜索组件的位置,但Espresso无法从resourcse访问这些组件。例如找不到android.R.id.search_close_btn。知道怎么测试吗?
onView(withId(android.R.id.search_close_btn)).perform(click));
或
onView(withId(android.R.id.search_src_text)).perform(click));
答案 0 :(得分:1)
使用onView(withText("Clear query")).perform(click));
,这将搜索包含内容说明的视图。
答案 1 :(得分:0)
有时,视图没有任何文字或ID,但它有一个内容描述,如“按回”。在这种情况下,您可以使用withContentDescription()
Espresso匹配器,例如:
onView(withContentDescription("Press back")).perform(click());