Espresso:No 层次结构中的视图发现与 ID 匹配:android:id/home
Espresso:No views in hierarchy found matching with id: android:id/home
当我 运行 我的测试用例时,我遇到了异常。
android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id: android:id/home
这是我的测试用例代码。
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 的视图?
我有 Google 我的问题,但答案不是我想要的。
感谢您的帮助。
和这里一样的问题(click home icon with espresso)
这条线解决了我的问题
Espresso.pressBack();
当我 运行 我的测试用例时,我遇到了异常。
android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id: android:id/home
这是我的测试用例代码。
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 的视图?
我有 Google 我的问题,但答案不是我想要的。
感谢您的帮助。
和这里一样的问题(click home icon with espresso)
这条线解决了我的问题
Espresso.pressBack();