Issue
I have this piece of code
private void setupDrawerLayout() {
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
final int itemId = menuItem.getItemId();
switch (itemId) {
case R.id.drawer_my_mixes:
replaceFragment(MyMixesFragment.newInstance());
drawerLayout.closeDrawers();
break;
and so on...
I want to make espresso to click R.id.drawer_settings
which will basically open a fragment called SettingsFragment. How do I do this? I tried this with no success
private ViewInteraction navigateToSettings(){
openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());
return onView(withText("Settings")).perform(click());
}
Solution
The correct way would be to use the onData function of Espresso.
onData(allOf(is(instanceOf(NavigationMenuItem.class)), ... )).perform(click());
But NavigationMenuItem isn't accessible since it is a private nested class.
An issue is pending https://code.google.com/p/android/issues/detail?id=187701 to find a solution on it. Go add a star to it ;-)
Answered By - Pol
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.