Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clicking on a menu item in action bar with Espresso when using onView(withId(...))

I am making a test using Espresso, first I open the action bar:

openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());

Everything ok up to here, but then I want to click on an option menu:

onView(withId(R.id.action_menu)).perform(click());

The menu layout xml has an option with id: "action_menu".

I get an error:

android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id: ***.********.******.android.debug:id/action_menu
If the target view is not part of the view hierarchy, you may need to use Espresso.onData to load it from one of the following AdapterViews:android.support.v7.widget.ListPopupWindow$DropDownListView{43fd3f58 VFED.VC. .F...... 24,24-612,168}

I got this step to work by using:

onView(withText(R.string.action_report)).perform(click());

I would like to know what is going wrong with the id though.

Any ideas?

like image 623
Romina Liuzzi Avatar asked Feb 26 '16 11:02

Romina Liuzzi


1 Answers

It seems that the view representing the menu does not know the id, but only the text of an item. I am new to Espresso and therefore cannot give more details, but this post is related to your problem : Espresso NoMatchingViewException when using withId matcher

like image 121
Coralie B Avatar answered Oct 22 '22 05:10

Coralie B