Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 279
Cyrus Avatar asked May 10 '17 07:05

Cyrus


1 Answers

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

Espresso.pressBack();
like image 159
Cyrus Avatar answered Nov 12 '22 16:11

Cyrus