How to click on index on option menu using Espresso Android

By : Moody
Source: Stackoverflow.com
Question!

I call on option menu using this code:
openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());

After that, the menu appeared. Now I click on the menu item by its text, and that is fine.

The problem that I already noticed is is subject, which can change, let's say if user uses many languages for different clients. So in the long test run it's not useful.

For that reason I want to use Espresso to click on specific index for specific test case.

The settings menu does not seems to have an ID. So I don't know how to click on specific item 'index' in that menu, let's say I want to click at fourth item.

Could you help me with solve it?

By : Moody


Answers

I just selected the menu item based on his ID.

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

Hope that work for you too.



This video can help you solving your question :)
By: admin