如何测试由sdk提供的espresso android原生组件,例如机器人:ID / search_close_btn

时间:2015-10-07 20:30:04

标签: android android-espresso

测试我们在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));

2 个答案:

答案 0 :(得分:1)

使用onView(withText("Clear query")).perform(click));,这将搜索包含内容说明的视图。

答案 1 :(得分:0)

有时,视图没有任何文字或ID,但它有一个内容描述,如“按回”。在这种情况下,您可以使用withContentDescription() Espresso匹配器,例如:

onView(withContentDescription("Press back")).perform(click());