[英]Espresso:No views in hierarchy found matching with id: android:id/home
当我运行我的测试用例时,我得到了例外。
android.support.test.espresso.NoMatchingViewException:找不到层次结构中的视图匹配:id:android:id / home
这是我的TestCase代码。
public void nav_to_alarm_test(){
onView(withId(R.id.navigation_notifications)).perform(click());
onView(withId(R.id.rl_reminder)).perform(click());
onView(withId(R.id.item_test)).perform(click());
onView(withId(android.R.id.home)).perform(click());//throw exception here
onView(withId(android.R.id.home)).perform(click());
}
这是android.R.id.home,属于ActionBar提供的按钮
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
case R.id.item_test:
startActivityForResult(CreateOrUpdateReminderActivity.class,CMD_ADD_REMINDER);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
为什么在资源ID android.R.id.home的层次结构中找不到视图? 我有谷歌我的问题,但答案不是我想要的。
谢谢你的帮助。
像这里一样的问题( 点击带有浓缩咖啡的主页图标 )
什么解决了我的问题是这一行
Espresso.pressBack();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.