Cyrus Cyrus - 1 year ago 150
Android Question

Espresso:No views in hierarchy found matching with id: android:id/home

When i run my test case,I got follow exception .


android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id: android:id/home


This is my TestCase code.

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());
}


This is
android.R.id.home,belongs to button provided by 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);

}
}


why can't find views in hierarchy for resource id android.R.id.home?
I have Google my problem, but answers isn't what i want.

Thanks for any help.

Answer Source

Same question like here(click home icon with espresso)
what solve my question is this line

Espresso.pressBack();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download