2016-03-11 7 views

答えて

18
@Test 
public void clickOnYourNavigationItem_ShowsYourScreen() { 
    // Open Drawer to click on navigation. 
    onView(withId(R.id.drawer_layout)) 
     .check(matches(isClosed(Gravity.LEFT))) // Left Drawer should be closed. 
     .perform(DrawerActions.open()); // Open Drawer 

    // Start the screen of your activity. 
    onView(withId(R.id.nav_view)) 
     .perform(NavigationViewActions.navigateTo(R.id.your_navigation_menu_item)); 

    // Check that you Activity was opened. 
    String expectedNoStatisticsText = InstrumentationRegistry.getTargetContext() 
     .getString(R.string.no_item_available); 
    onView(withId(R.id.no_statistics)).check(matches(withText(expectedNoStatisticsText))); 
} 

これはまさにあなたが探しているものです。

他の例は、カスタムViewActionで `navigateTo`のソースコードのリンクが壊れているようhereまたはhere

+0

が見える可能です。 –

+0

@SudarsanGPあなたは正しいです。それはアンドロイドSDKに追加されたようです。私は答えの参照を更新するつもりです。 'android.support.test.espresso.contrib'で定義された' NavigationViewActions'を使うだけです – GVillani82

関連する問題