@Test public void testDescriptionExpand() { setupMockServer(null); activityRule.launchActivity(intent); TimingIdlingResource idlingResource = new TimingIdlingResource(3000); // wait dummy network operation Espresso.registerIdlingResources(idlingResource); onView(withId(R.id.description)) .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); onView(withId(R.id.description_parent)).perform(click()); onView(withId(R.id.description)) .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); Espresso.unregisterIdlingResources(idlingResource); }
@Test public void goUserPageFromComment() { setupMockServer(null); activityRule.launchActivity(intent); TimingIdlingResource idlingResource = new TimingIdlingResource(3000); // wait dummy network operation Espresso.registerIdlingResources(idlingResource); onView(withId(R.id.comment_parent)).perform(clickComment()); Espresso.unregisterIdlingResources(idlingResource); Instrumentation.ActivityMonitor receiverActivityMonitor = InstrumentationRegistry.getInstrumentation() .addMonitor(UserActivity.class.getName(), null, false); Activity activity = receiverActivityMonitor.waitForActivityWithTimeout(1000); assertEquals("Launched Activity is not UserActivity", UserActivity.class, activity.getClass()); onView(withText("¡! Nature B■x !¡")).check(matches(isDisplayed())); pressBack(); SystemClock.sleep(2000); }
/** * Helper method that waits until the given Snackbar has been fully dismissed. Note that calling * this method will reset the currently set {@link Snackbar.Callback}. */ public static void waitUntilFullyDismissed(Snackbar snackbar) { SnackbarDismissedCallback snackbarCallback = new SnackbarDismissedCallback(); snackbar.setCallback(snackbarCallback); try { // Register our listener as idling resource so that Espresso waits until the // the snackbar has been fully dismissed Espresso.registerIdlingResources(snackbarCallback); // Mark the callback to require waiting for idle state snackbarCallback.mNeedsIdle = true; // Perform a dummy Espresso action that loops until the UI thread is idle. This // effectively blocks us until the Snackbar has completed its sliding animation. onView(isRoot()).perform(waitUntilIdle()); snackbarCallback.mNeedsIdle = false; } finally { // Unregister our idling resource Espresso.unregisterIdlingResources(snackbarCallback); // And remove our tracker listener from Snackbar snackbar.setCallback(null); } }
/** TODO: Passed List data and detail data is wrong item */ @Test public void checkDetailInfo_isSet() { setupMockServer(null); activityRule.launchActivity(intent); onView(withId(R.id.title)) .check(matches(withText("A Quiet Evening"))); // we know its title from list onView(withId(R.id.user_name)).check(matches(withText(""))); onView(withId(R.id.description)).check(matches(withText(""))); onView(withId(R.id.date_text)).check(matches(withText(""))); TimingIdlingResource idlingResource = new TimingIdlingResource(3000); // wait dummy network operation Espresso.registerIdlingResources(idlingResource); onView(withId(R.id.title)).check(matches(withText("Sundown on the Oregon Coast"))); onView(withId(R.id.user_name)).check(matches(withText("Cole Chase Photography"))); onView(withId(R.id.description)).check(matches(startsWith("I was treated to this"))); onView(withId(R.id.date_text)).check(matches(withText("Posted on 2015-08-02 22:40:28"))); onView(withId(R.id.comment_parent)).check(matches(withChildOn(0, "C'est magnifique !"))); onView(withId(R.id.comment_parent)).check(matches(withChildOn(1, "A wonderful moment"))); onView(withId(R.id.comment_parent)).check(matches(withChildOn(2, "beautiful capture Cole"))); onView(withId(R.id.comment_parent)).check(matches(withChildOn(3, "See All 35 Comments"))); Espresso.unregisterIdlingResources(idlingResource); }
@After public void unregisterIdlingResource() { Espresso.unregisterIdlingResources(idlingResource); }
/** * Unregister your Idling Resource so it can be garbage collected and does not leak any memory. */ @After public void unregisterIdlingResource() { Espresso.unregisterIdlingResources( mAddNoteIntentsTestRule.getActivity().getCountingIdlingResource()); }