@Test public void challengeRequestAccept() { // Send message sendTestMessage(Message.Type.CHALLENGE_REQUEST, Challenge.Type.DISTANCE, true); //Tap on the request onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_messages)); onView(isRoot()).perform(waitForMatch(withId(R.id.list), UI_TEST_TIMEOUT)); onData(anything()).inAdapterView(withId(R.id.list)).atPosition(0).perform(click()); //Tap on Accept tryIsDisplayed(withId(R.id.request_layout), UI_TEST_TIMEOUT); onView(withId(R.id.accept_btn)).perform(click()); onView(isRoot()).perform(waitForMatch(withId(R.id.readyBtn), UI_TEST_TIMEOUT)); //Delete challenges from firebase new FirebaseHelper().deleteChallengeNode("Runnest IHL vs Test User test1"); }
@Test public void scheduleMessageCancelAndAccept() { // Send message sendTestMessage(Message.Type.SCHEDULE_REQUEST, Challenge.Type.DISTANCE, false); //Tap on the request onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_messages)); //Tap on Cancel onView(isRoot()).perform(waitForMatch(withId(R.id.list), UI_TEST_TIMEOUT)); onData(anything()).inAdapterView(withId(R.id.list)).atPosition(0).perform(click()); tryIsDisplayed(withId(R.id.cancel_btn), UI_TEST_TIMEOUT); onView(withId(R.id.cancel_btn)).perform(click()); //Tap on Accept onView(isRoot()).perform(waitForMatch(withId(R.id.list), UI_TEST_TIMEOUT)); onData(anything()).inAdapterView(withId(R.id.list)).atPosition(0).perform(click()); tryIsDisplayed(withId(R.id.accept_btn), UI_TEST_TIMEOUT); onView(withId(R.id.accept_btn)).perform(click()); }
@Test public void scheduleMessageDecline() { // Send message sendTestMessage(Message.Type.SCHEDULE_REQUEST, Challenge.Type.TIME, false); //Tap on the request onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_messages)); //Tap on Decline onView(isRoot()).perform(waitForMatch(withId(R.id.list), UI_TEST_TIMEOUT)); onData(anything()).inAdapterView(withId(R.id.list)).atPosition(0).perform(click()); tryIsDisplayed(withId(R.id.decline_btn), UI_TEST_TIMEOUT); onView(withId(R.id.decline_btn)).perform(click()); onView(isRoot()).perform(waitForMatch(withId(R.id.list), UI_TEST_TIMEOUT)); }
@Test public void memoMessageCloseDelete() { // Send message sendTestMessage(Message.Type.MEMO, Challenge.Type.TIME, false); //Tap on the request onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_messages)); onView(isRoot()).perform(waitForMatch(withId(R.id.list), UI_TEST_TIMEOUT)); onData(anything()).inAdapterView(withId(R.id.list)).atPosition(0).perform(click()); //Tap on Close tryIsDisplayed(withId(R.id.cancel_btn), UI_TEST_TIMEOUT); onView(withId(R.id.cancel_btn)).perform(click()); //Tap on Delete onView(isRoot()).perform(waitForMatch(withId(R.id.list), UI_TEST_TIMEOUT)); onData(anything()).inAdapterView(withId(R.id.list)).atPosition(0).perform(click()); tryIsDisplayed(withId(R.id.decline_btn), UI_TEST_TIMEOUT); onView(withId(R.id.decline_btn)).perform(click()); onView(isRoot()).perform(waitForMatch(withId(R.id.list), UI_TEST_TIMEOUT)); }
@Test public void memoMessageChallenge() { // Send message sendTestMessage(Message.Type.MEMO, Challenge.Type.DISTANCE, false); //Tap on the request onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_messages)); onView(isRoot()).perform(waitForMatch(withId(R.id.list), UI_TEST_TIMEOUT)); onData(anything()).inAdapterView(withId(R.id.list)).atPosition(0).perform(click()); //Tap on Challenge tryIsDisplayed(withId(R.id.accept_btn), UI_TEST_TIMEOUT); onView(withId(R.id.accept_btn)).perform(click()); tryIsDisplayed(withId(R.id.time_radio), UI_TEST_TIMEOUT); }
@Test public void runFragmentLifecycleTest() { onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_run)); // Jenkins sleep (1/3) // // Sleep necessary in order to successfully build on Jenkins, I wasn't able to // reproduce the failure in local. After a lot of attempts I decided to keep it. SystemClock.sleep(FIREBASE_DURATION); onView(isRoot()).perform(waitForMatch(withId(R.id.start_run), UI_TEST_TIMEOUT)); activityRule.getActivity().finish(); activityRule.getActivity(); }
@Test public void startAndStopRun() { onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_run)); // Jenkins sleep (1/3) // // Sleep necessary in order to successfully build on Jenkins, I wasn't able to // reproduce the failure in local. After a lot of attempts I decided to keep it. SystemClock.sleep(FIREBASE_DURATION); onView(isRoot()).perform(waitForMatch(withId(R.id.start_run), UI_TEST_TIMEOUT)); onView(withId(R.id.start_run)).perform(click()); SystemClock.sleep(MOCK_LOCATION_DURATION); onView(isRoot()).perform(waitForMatch(withId(R.id.stop_run), UI_TEST_TIMEOUT)); onView(withId(R.id.stop_run)).perform(click()); onView(isRoot()).perform(waitForMatch(withId(R.id.button_history), UI_TEST_TIMEOUT)); onView(withId(R.id.button_history)).perform(click()); }
@Test public void navigateToLogout() { // Logout cancel onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_logout)); tryIsDisplayed(withId(android.R.id.button2), UI_TEST_TIMEOUT); onView(withId(android.R.id.button2)).perform(click()); // Logout ok onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_logout)); tryIsDisplayed(withId(android.R.id.button2), UI_TEST_TIMEOUT); onView(withText("OK")).perform(click()); onView(isRoot()).perform(waitForMatch(withId(R.id.sign_in_button), UI_TEST_TIMEOUT)); }
@Test public void inviteWasNotSent() { Instrumentation.ActivityResult result = new Instrumentation .ActivityResult(Activity.RESULT_CANCELED, null); intending(toPackage("com.google.android.gms")).respondWith(result); waitView(() -> onView(withId(R.id.fab)).check(matches(isDisplayed()))); onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); waitView(() -> onView(withId(R.id.nav_view)).check(matches(isDisplayed()))); onView(withId(R.id.nav_view)) .perform(NavigationViewActions.navigateTo(R.id.nav_invite)); intended(allOf(hasAction("com.google.android.gms.appinvite.ACTION_APP_INVITE"), toPackage("com.google.android.gms"))); onView(withText(R.string.invitation_failed_message)) .inRoot(withDecorView(not(mActivityRule.getActivity().getWindow().getDecorView()))) .check(matches(isDisplayed())); }
@Test public void inviteSent() { Instrumentation.ActivityResult result = new Instrumentation .ActivityResult(Activity.RESULT_OK, null); intending(toPackage("com.google.android.gms")).respondWith(result); waitView(() -> onView(withId(R.id.fab)).check(matches(isDisplayed()))); onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); waitView(() -> onView(withId(R.id.nav_view)).check(matches(isDisplayed()))); onView(withId(R.id.nav_view)) .perform(NavigationViewActions.navigateTo(R.id.nav_invite)); intended(allOf(hasAction("com.google.android.gms.appinvite.ACTION_APP_INVITE"), toPackage("com.google.android.gms"))); waitView(() -> onView(withText(R.string.invitation_sent_message)) .inRoot(withDecorView(not(mActivityRule.getActivity().getWindow().getDecorView()))) .check(matches(isDisplayed()))); }
@Test public void sendFeedbackEmailTest() { Context context = mActivityRule.getActivity().getBaseContext(); intending(toPackage("android.intent.action.CHOOSER")); waitView(() -> onView(withId(R.id.fab)).check(matches(isDisplayed()))); onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); waitView(() -> onView(withId(R.id.nav_view)).check(matches(isDisplayed()))); waitView(() -> onView(withId(R.id.nav_view)) .perform(NavigationViewActions.navigateTo(R.id.nav_contact_us))); intended(allOf( hasAction("android.intent.action.CHOOSER"), hasExtra("android.intent.extra.TITLE", context. getString(R.string.send_email_intent_chooser_message)))); }
@Test public void challengeRequestCancelAndDecline() { // Send message sendTestMessage(Message.Type.CHALLENGE_REQUEST, Challenge.Type.TIME, true); //Tap on the request onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_messages)); //Tap on Cancel onView(isRoot()).perform(waitForMatch(withId(R.id.list), UI_TEST_TIMEOUT)); onData(anything()).inAdapterView(withId(R.id.list)).atPosition(0).perform(click()); SystemClock.sleep(FIREBASE_DURATION); tryIsDisplayed(withId(R.id.request_layout), UI_TEST_TIMEOUT); onView(withId(R.id.cancel_btn)).perform(click()); //Tap on Decline onView(isRoot()).perform(waitForMatch(withId(R.id.list), UI_TEST_TIMEOUT)); onData(anything()).inAdapterView(withId(R.id.list)).atPosition(0).perform(click()); tryIsDisplayed(withId(R.id.request_layout), UI_TEST_TIMEOUT); onView(withId(R.id.decline_btn)).perform(click()); onView(isRoot()).perform(waitForMatch(withId(R.id.list), UI_TEST_TIMEOUT)); //Delete challenges from firebase new FirebaseHelper().deleteChallengeNode("Runnest IHL vs Test User test1"); }
@Test public void memoMessageBusyChallenge() { // Send message Message msg1 = new Message("busyEmail", "Test User", "busyUser", "Test User", Message.Type.MEMO, "test1", new Date(), 1, 0, Challenge.Type.DISTANCE); FirebaseHelper firebaseHelper = new FirebaseHelper(); firebaseHelper.sendMessage(msg1); // Needed to be sure that the sent message appears on firebase SystemClock.sleep(FIREBASE_DURATION); //Tap on the request onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_messages)); onView(isRoot()).perform(waitForMatch(withId(R.id.list), UI_TEST_TIMEOUT)); onData(anything()).inAdapterView(withId(R.id.list)).atPosition(0).perform(click()); //Tap on Challenge tryIsDisplayed(withId(R.id.accept_btn), UI_TEST_TIMEOUT); onView(withId(R.id.accept_btn)).perform(click()); }
@Test public void displayChallenge() { onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_history)); onView(isRoot()).perform(waitForMatch(withId(R.id.tabs), UI_TEST_TIMEOUT)); onView(allOf(withText("Challenges"), isDescendantOfA(withId(R.id.tabs)))).perform(click()); onView(isRoot()).perform(waitForMatch(withId(R.id.list), UI_TEST_TIMEOUT)); onData(anything()).inAdapterView(withId(R.id.list)).atPosition(0).perform(click()); }
@Test public void startAndAbortRun() { onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_run)); // Jenkins sleep (2/3) // // Sleep necessary in order to successfully build on Jenkins, I wasn't able to // reproduce the failure in local. After a lot of attempts I decided to keep it. SystemClock.sleep(FIREBASE_DURATION); onView(isRoot()).perform(waitForMatch(withId(R.id.start_run), UI_TEST_TIMEOUT)); onView(withId(R.id.start_run)).perform(click()); SystemClock.sleep(MOCK_LOCATION_DURATION); //Press on CANCEL pressBack(); tryIsDisplayed(withId(android.R.id.button2), UI_TEST_TIMEOUT); onView(withId(android.R.id.button2)).perform(click()); onView(isRoot()).perform(waitForMatch(withId(R.id.stop_run), UI_TEST_TIMEOUT)); pressBack(); tryIsDisplayed(withId(android.R.id.button1), UI_TEST_TIMEOUT); onView(withId(android.R.id.button1)).perform(click()); onView(isRoot()).perform(waitForMatch(withId(R.id.main_layout), UI_TEST_TIMEOUT)); }
@Test public void deleteRun() { onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_run)); // Jenkins sleep (3/3) // // Sleep necessary in order to successfully build on Jenkins, I wasn't able to // reproduce the failure in local. After a lot of attempts I decided to keep it. SystemClock.sleep(FIREBASE_DURATION); onView(isRoot()).perform(waitForMatch(withId(R.id.start_run), UI_TEST_TIMEOUT)); onView(withId(R.id.start_run)).perform(click()); SystemClock.sleep(MOCK_LOCATION_DURATION); onView(isRoot()).perform(waitForMatch(withId(R.id.stop_run), UI_TEST_TIMEOUT)); onView(withId(R.id.stop_run)).perform(click()); // Exit and enter displayChallenge tryIsDisplayed(withId(R.id.button_history), TIME_CHALLENGE_DURATION + UI_TEST_TIMEOUT); onView(withId(R.id.button_history)).perform(click()); onView(isRoot()).perform(waitForMatch(withId(R.id.tabs), UI_TEST_TIMEOUT)); onView(allOf(withText("Runs"), isDescendantOfA(withId(R.id.tabs)))).perform(click()); onView(isRoot()).perform(waitForMatch(withId(R.id.list), UI_TEST_TIMEOUT)); onData(anything()).inAdapterView(withId(R.id.list)).atPosition(0).perform(click()); onView(isRoot()).perform(waitForMatch(withId(R.id.button_delete), UI_TEST_TIMEOUT)); onView(withId(R.id.button_delete)).perform(click()); onView(isRoot()).perform(waitForMatch(withId(R.id.tabs), UI_TEST_TIMEOUT)); }
@Test public void displayRun() { onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_history)); onView(isRoot()).perform(waitForMatch(withId(R.id.tabs), UI_TEST_TIMEOUT)); onView(allOf(withText("Runs"), isDescendantOfA(withId(R.id.tabs)))).perform(click()); onView(isRoot()).perform(waitForMatch(withId(R.id.list), UI_TEST_TIMEOUT)); onData(anything()).inAdapterView(withId(R.id.list)).atPosition(0).perform(click()); }
@Test public void navigateToChallengeHistory() { onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_history)); onView(isRoot()).perform(waitForMatch(withId(R.id.tabs), UI_TEST_TIMEOUT)); onView(allOf(withText("Challenges"), isDescendantOfA(withId(R.id.tabs)))).perform(click()); }
@Test public void navigateToSingleRunHistory() { onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_history)); onView(isRoot()).perform(waitForMatch(withId(R.id.tabs), UI_TEST_TIMEOUT)); onView(allOf(withText("Runs"), isDescendantOfA(withId(R.id.tabs)))).perform(click()); onView(allOf(withText("Challenges"), isDescendantOfA(withId(R.id.tabs)))).perform(click()); onView(allOf(withText("Runs"), isDescendantOfA(withId(R.id.tabs)))).perform(click()); }
@Test public void backButtonWorks() { onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_run)); onView(isRoot()).perform(waitForMatch(withId(R.id.start_run), UI_TEST_TIMEOUT)); Espresso.pressBack(); onView(isRoot()).perform(waitForMatch(withId(R.id.main_layout), UI_TEST_TIMEOUT)); }
private static void signOut() { waitView(() -> onView(withId(R.id.fab)).check(matches(isDisplayed()))); onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); waitView(() -> onView(withId(R.id.nav_view)).check(matches(isDisplayed()))); waitView(() -> onView(withId(R.id.nav_view)) .perform(NavigationViewActions.navigateTo(R.id.nav_sign_out))); onView(withText(R.string.sign_out)).check(matches(isDisplayed())); onView(withText(R.string.sign_out)).perform(click()); waitView(() -> onView(withId(R.id.sign_in_button)).check(matches(isDisplayed()))); }
@Test public void signOut() { waitView(() -> onView(withId(R.id.fab)).check(matches(isDisplayed()))); onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); waitView(() -> onView(withId(R.id.nav_view)).check(matches(isDisplayed()))); waitView(() -> onView(withId(R.id.nav_view)) .perform(NavigationViewActions.navigateTo(R.id.nav_sign_out))); onView(withText(R.string.sign_out)).check(matches(isDisplayed())); onView(withText(R.string.sign_out)).perform(click()); }
@Test public void navigateToRunningMap() { onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_run)); }
@Test public void navigateToRunHistory() { onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_history)); }
@Test public void navigateToMessages() { onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_messages)); }
@Test public void navigateToProfile() { onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_profile)); }
@Test public void navigateToNewChallenge() { onView(withId(R.id.drawer_layout)).perform(DrawerActions.open()); onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_new_challenge)); onView(isRoot()).perform(waitForMatch(withId(R.id.empty_layout), UI_TEST_TIMEOUT)); }