Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Pavneet-Sing/d9745326605fa9068e081436cff9b45f to your computer and use it in GitHub Desktop.
Save Pavneet-Sing/d9745326605fa9068e081436cff9b45f to your computer and use it in GitHub Desktop.
public class AppNavigationTest {
@Rule
public ActivityTestRule<NewsActivity> activityTestRule =
new ActivityTestRule<>(NewsActivity.class);
@Before
public void registerIdlingResource() {
// let espresso know to synchronize with background tasks
IdlingRegistry.getInstance().register(EspressoTestingIdlingResource.getIdlingResource());
}
@After
public void unregisterIdlingResource() {
IdlingRegistry.getInstance().unregister(EspressoTestingIdlingResource.getIdlingResource());
}
@Test
public void verifyDetailsIntent() {
// check views are displayed or not
onView(withId(R.id.swipe_msg_tv)).check(matches(isDisplayed()));
// perform swipe down gesture to initiate network request
onView(withId(R.id.swipe_container)).perform(swipeDown());
// make sure the empty message is not displayed anymore
onView(withId(R.id.swipe_msg_tv)).check(matches(not(isDisplayed())));
// make sure list is visible
onView(withId(R.id.news_frag_recycler_list)).check(matches(isDisplayed()));
// perform click on third item in the list
onView(withId(R.id.news_frag_recycler_list))
.perform(RecyclerViewActions.actionOnItemAtPosition(3, click()));
// setup code to imitate the action of opening browser
Intents.init();
Matcher<Intent> expectedIntent = hasAction(Intent.ACTION_VIEW);
intending(expectedIntent).respondWith(new Instrumentation.ActivityResult(0, null));
onView(withText(R.string.details_story_link)).perform(click());
intended(expectedIntent);
Intents.release();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment