类android.support.test.espresso.contrib.DrawerActions源码实例Demo

下面列出了怎么用android.support.test.espresso.contrib.DrawerActions的API类实例代码及写法,或者点击链接到github查看源代码。

/**
 * Check if the username, password and userAvatar are visible and verify when click on
 * userAvatar UserProfileActivity will open
 */
@Test
public void checkAllViewsVisible_and_OnClickAvatar_openUserProfileActivity() throws Exception {

    Intents.init();
    onView(withId(R.id.drawer_layout))
            .check(matches(isClosed(Gravity.LEFT)))
            .perform(DrawerActions.open());

    //Please Login first otherwise it will not find username and email
    onView(withId(R.id.nav_user_avatar)).check(matches((isDisplayed())));
    onView(withId(R.id.nav_user_name)).check(matches((isDisplayed())));
    onView(withId(R.id.nav_user_email)).check(matches((isDisplayed())));

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

    intended(hasComponent(UserProfileActivity.class.getName()));
    Intents.release();
}
 
/**
 * Checks if the usage activity is launched when we click on usage in nav drawer
 */
@Test
public void onClickNavUsage_openUsageActivity() throws Exception {

    Intents.init();

    onView(withId(R.id.drawer_layout))
            .check(matches(isClosed(Gravity.LEFT)))
            .perform(DrawerActions.open());

    onView(withId(R.id.nav_view))
            .perform(NavigationViewActions.navigateTo(R.id.nav_usage));

    intended(hasComponent(UsageActivity.class.getName()));

    Intents.release();
}
 
/**
 * Checks if the login is launched when click on logout in nav drawer and click on
 * sign out in alert dialouge box
 */
@Test
public void onClickLogout_ClickSignOut_OpenLoginScreen() throws Exception {

    Intents.init();
    onView(withId(R.id.drawer_layout))
            .check(matches(isClosed(Gravity.LEFT)))
            .perform(DrawerActions.open());

    onView(withId(R.id.nav_view))
            .perform(NavigationViewActions.navigateTo(R.id.nav_logout));

    onView(withId(android.R.id.button1)).perform(click());

    intended(hasComponent(LoginActivity.class.getName()));

    Intents.release();
}
 
/**
 * Checks if alert dialogue box is dismiss when click on cancel in logout alert sign in box
 */
@Test
public void onClickLogout_clickCancel_dismissDialogueBoz() throws Exception {

    Intents.init();
    onView(withId(R.id.drawer_layout))
            .check(matches(isClosed(Gravity.LEFT)))
            .perform(DrawerActions.open());

    onView(withId(R.id.nav_view))
            .perform(NavigationViewActions.navigateTo(R.id.nav_logout));

    onView(withId(android.R.id.button2)).perform(click());

    onView(withId(R.id.drawer_layout))
            .check(matches(isOpen(Gravity.LEFT)));

    Intents.release();
}
 
源代码5 项目: Awesome-WanAndroid   文件: AppNavigationTest.java
private void openNavigationItem(@IdRes int itemId) {
    onView(withId(R.id.drawer_layout))
            .check(matches(DrawerMatchers.isClosed(Gravity.LEFT)))
            .perform(DrawerActions.open());

    onView(withId(R.id.nav_view))
            .perform(NavigationViewActions.navigateTo(itemId));
}
 
源代码6 项目: Awesome-WanAndroid   文件: AppNavigationTest.java
private void openLoginPage() {
    onView(withId(R.id.drawer_layout))
            .check(matches(DrawerMatchers.isClosed(Gravity.LEFT)))
            .perform(DrawerActions.open());

    clickView(R.id.nav_header_login_tv);
}
 
/**
 * Gets the activity and navigates to the Class's category in the navigation drawer
 *
 * Uses espresso-contrib dor navigation drawer and recyclerView support
 *
 * @throws Exception instrumentation ActivityInstrumentationTestCase2 exception
 */
@Override
protected void setUp() throws Exception {
    getActivity(); //IMPORTANT you must call this before your tests!
    super.setUp();
    DrawerActions.openDrawer(R.id.drawer_layout);
    RecyclerViewActions.scrollTo(withText(getClassName()));
    onView(withId(R.id.drawerList)).perform(RecyclerViewActions.actionOnItem(hasDescendant(withText(getClassName())), click()));
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
}
 
/**
 * Checks if the Workflow fragment is launched when we click on Workflow in nav drawer
 */
@Test
public void onClickNavAllWorkflows_openWorkflowsFragment() throws Exception {

    onView(withId(R.id.drawer_layout))
            .check(matches(isClosed(Gravity.LEFT)))
            .perform(DrawerActions.open());

    onView(withId(R.id.nav_view))
            .perform(NavigationViewActions.navigateTo(R.id.nav_workflows));

    onView(withId(R.id.frame_container)).check(matches((isDisplayed())));

}
 
/**
 * Checks if the myWorkflow fragment is launched when we click on myWorkflow in nav drawer.
 * Without login, The app does not have any user then it also does not have any myworkflow
 * Without login it will fail
 */
@Test
public void onClickNavMyWorkflows_openMyWorkflowActivity() throws Exception {

    onView(withId(R.id.drawer_layout))
            .check(matches(isClosed(Gravity.LEFT)))
            .perform(DrawerActions.open());

    onView(withId(R.id.nav_view))
            .perform(NavigationViewActions.navigateTo(R.id.nav_my_workflows));

    onView(withId(R.id.frame_container)).check(matches((isDisplayed())));

}
 
/**
 * Checks if the About dialouge is launched when we click on about in nav drawer
 */
@Test
public void onClickNavAbout_checkAboutDialogue() throws Exception {

    onView(withId(R.id.drawer_layout))
            .check(matches(isClosed(Gravity.LEFT)))
            .perform(DrawerActions.open());

    onView(withId(R.id.nav_view))
            .perform(NavigationViewActions.navigateTo(R.id.nav_about));

    onView(withId(R.id.about_dialouge_layout)).check(matches((isDisplayed())));

}
 
/**
 * Checks if the Licence dialouge is launched when we click on licence in nav drawer
 */
@Test
public void onClickNavLicence_openLicenceDialouge() throws Exception {

    onView(withId(R.id.drawer_layout))
            .check(matches(isClosed(Gravity.LEFT)))
            .perform(DrawerActions.open());

    onView(withId(R.id.nav_view))
            .perform(NavigationViewActions.navigateTo(R.id.os_licences));

    onView(withText(R.string.title_nav_os_licences)).check(matches(isDisplayed()));

}
 
/**
 * Checks if the Licence dialogue is launched when we click on licence in nav drawer
 */
@Test
public void onClickNavApacheLicence_openApacheLicence_NoticeDialouge() throws Exception {

    onView(withId(R.id.drawer_layout))
            .check(matches(isClosed(Gravity.LEFT)))
            .perform(DrawerActions.open());

    onView(withId(R.id.nav_view))
            .perform(NavigationViewActions.navigateTo(R.id.apache_licences));

    onView(withText(R.string.title_nav_apache_licences)).check(matches(isDisplayed()));

}
 
/**
 * Checks if the setting fragment is launched
 * when we click on settings in navigation drawer
 */
@Test
public void onClickNavSetting_openSettingFragment() throws Exception {

    onView(withId(R.id.drawer_layout))
            .check(matches(isClosed(Gravity.LEFT)))
            .perform(DrawerActions.open());

    onView(withId(R.id.nav_view))
            .perform(NavigationViewActions.navigateTo(R.id.nav_settings));

    onView(withId(R.id.frame_container)).check(matches((isDisplayed())));

}
 
/**
 * Checks if the favoriteWorkflow fragment is launched when we click on
 * favoriteWorkflow in nav drawer
 */
@Test
public void onClickNavFavWorkflows_openFavoriteWorkflowActivity() throws Exception {

    onView(withId(R.id.drawer_layout))
            .check(matches(isClosed(Gravity.LEFT)))
            .perform(DrawerActions.open());

    onView(withId(R.id.nav_view))
            .perform(NavigationViewActions.navigateTo(R.id.nav_favourite_workflow));

    sleep(3000);

    onView(withId(R.id.frame_container)).check(matches((isDisplayed())));

}
 
/**
 * Checks if the Announcement fragment is launched when we click on
 * announcement in nav drawer
 */
@Test
public void onClickNavAnnouncement_openAnnouncementActivity() throws Exception {

    onView(withId(R.id.drawer_layout))
            .check(matches(isClosed(Gravity.LEFT)))
            .perform(DrawerActions.open());

    onView(withId(R.id.nav_view))
            .perform(NavigationViewActions.navigateTo(R.id.nav_announcement));

    sleep(3000);

    onView(withId(R.id.frame_container)).check(matches((isDisplayed())));

}
 
 类所在包
 同包方法