使用espresso测试Android NavigationView菜单项

时间:2015-12-25 01:51:27

标签: android testing android-espresso

我使用较新的菜单/ my-nav-menu.xml设置了NavigationDrawer和NavigationView,而不是使用适配器的ListView。作为使用Espresso进行自动化测试的一部分,我想断言给定的菜单项是可见的,然后单击该项。为了我的能见度检查,我尝试了以下......

onView(viewMatcher...).check(ViewAssertions.matches(isDisplayed()));

使用这个,我最终得到一个NoMatchingViewException。

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

从我收集的内容来看,菜单项可能在视图层次结构中不可见。有没有更多在Android上测试经验的人找到了解决方法?

1 个答案:

答案 0 :(得分:0)

即使菜单项当前不可见而且它在其他地方

,这将导航到注册页面
onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id. nav_register));
相关问题