@Test public void preConditions() { ImageDetailActivity activity = activityRule.launchActivity(intent); onView(withId(R.id.container)) .check(matches(ViewMatchers.withContentDescription(R.string.detail_container))); String args = activity.getIntent().getStringExtra(ImageDetailActivity.EXTRA_CONTENT); assertEquals(args, DataHolder.LIST_ITEM_JSON); }
@Test public void enviamosUnDatito() { Intent intent = new Intent(); intent.putExtra("data", THIS_IS_MY_BOMB); activityTestRule.launchActivity(intent); onView(withId(R.id.txt_receiver)).check(matches(withText(THIS_IS_MY_BOMB))); }
@Test public void nullCommentHandling() { HashMap<String, String> map = new HashMap<>(); map.put( FlickrURL.COMMENT_LIST, "{\"comments\":{\"photo_id\":\"21043155476\"},\"stat\":\"ok\"}"); setupMockServer(map); activityRule.launchActivity(intent); SystemClock.sleep(3000); onView(withContentDescription("No Comment")).check(matches(withText(R.string.no_comment))); }
@Test public void testSingleStation() throws InterruptedException { when(availableStationsManager.isAvailable(any(Station.class))).thenReturn(true); defineMock(parseService, new StationList(new Station(0, 0, "aaaa"))); rule.launchActivity(null); onView(withId(R.id.total_count)).check(matches(withText("1"))); Spoon.screenshot(rule.getActivity(), "Single_station"); }
@Test public void testNoData() throws InterruptedException { when(availableStationsManager.isAvailable(any(Station.class))).thenReturn(true); defineMock(parseService, new StationList()); rule.launchActivity(null); onView(withId(R.id.no_data)).check(matches(isDisplayed())); Spoon.screenshot(rule.getActivity(), "No_data"); }
@Test public void shouldDisplayCardNumberError() { Intent intent = new Intent(); intent.putExtra(Judo.JUDO_OPTIONS, getJudo().build()); testRule.launchActivity(intent); onView(withId(R.id.card_number_edit_text)).perform(typeText("1111111111111111")); onView(withText("Check card number")).check(matches(isDisplayed())); onView(withId(R.id.pay_button)).check(matches(isNotDisplayed())); }
@Test public void shouldDisplayExpiryDateError() { Intent intent = new Intent(); intent.putExtra(Judo.JUDO_OPTIONS, getJudo().build()); testRule.launchActivity(intent); onView(withId(R.id.expiry_date_edit_text)).perform(typeText("1215")); onView(withText("Check expiry date")).check(matches(isDisplayed())); onView(withId(R.id.pay_button)).check(matches(isNotDisplayed())); }
@Test public void testPostsShowAndAreScrollableInFeed() { List<Long> postIdList = MockModelsUtil.createMockPostIdList(20); List<Post> postList = new ArrayList<>(); for (Long id : postIdList) { postList.add(MockModelsUtil.createMockStoryWithId(id)); } stubMockPosts(postIdList, postList); main.launchActivity(null); checkPostsDisplayOnRecyclerView(postList); }
@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 testJobPostHasViewButton() throws Exception { List<Long> postIdList = new ArrayList<>(); Post mockPost = MockModelsUtil.createMockJobWithTitle("Post with url"); postIdList.add(mockPost.id); when(component.getMockHackerNewsService().getTopStories()) .thenReturn(Observable.just(postIdList)); when(component.getMockHackerNewsService().getStoryItem(mockPost.id.toString())) .thenReturn(Observable.just(mockPost)); Intent i = new Intent(MainActivity.getStartIntent(InstrumentationRegistry.getTargetContext())); main.launchActivity(i); onView(withId(R.id.text_view_post)).check(matches(isDisplayed())); }
@Test public void shouldDisplaySubmitButtonWhenFormValid() { Intent intent = new Intent(); intent.putExtra(Judo.JUDO_OPTIONS, getJudo().build()); testRule.launchActivity(intent); onView(withId(R.id.pay_button)).check(matches(isNotDisplayed())); onView(withId(R.id.card_number_edit_text)).perform(typeText("4976000000003436")); onView(withId(R.id.expiry_date_edit_text)).perform(typeText("1220")); onView(withId(R.id.security_code_edit_text)).perform(typeText("452")); onView(withId(R.id.pay_button)).check(matches(isDisplayed())); }
@Test public void listOfRibotsShows() { List<Ribot> mockRibots = TestDataFactory.makeListRibots(20); when(component.getMockRibotsService().getRibots()).thenReturn(Observable.just(mockRibots)); main.launchActivity(null); int position = 0; for (Ribot mockRibot : mockRibots) { onView(withId(R.id.recycler_view)).perform(RecyclerViewActions.scrollToPosition(position)); String name = String.format("%s %s", mockRibot.profile.name.first, mockRibot.profile.name.last); onView(withText(name)).check(matches(isDisplayed())); onView(withText(mockRibot.profile.email)).check(matches(isDisplayed())); position++; } }
@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); }
@Test public void testLikeClickableJailed() { Context context = InstrumentationRegistry.getInstrumentation().getTargetContext(); SharedPreferences sharedPreferences = context.getSharedPreferences(JoinActivity.PREFS_NAME, Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.clear(); editor.commit(); editor.putString("logged", "logged"); editor.putInt("userId", -1); editor.putBoolean("jailed", true); editor.putInt("experience", 1000000); editor.commit(); Intent intent = new Intent(context, MainActivity.class); intent.putExtra(MainActivity.ROOM_NAME, "testroom"); mainActivityActivityTestRule.launchActivity(intent); }
@Test public void loadBookInfo_DisplayBookInformation() { Intent intent = new Intent(); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); BookDetailParcelable bookDetailParcelable = new BookDetailParcelable(); bookDetailParcelable.setBookDetailObjectId(BOOK_OBJ_ID); bookDetailParcelable.setBookTitle("Searching for Spring"); bookDetailParcelable.setBookImageUrl( "http://riggaroo.co.za/bookdash/3-fishgift/xhosa/1-cover.jpg"); intent.putExtra(BookInfoActivity.BOOK_PARCEL, bookDetailParcelable); activityTestRule.launchActivity(intent); onView(withText("Searching for Spring")) .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(withText("Rebecca Franks")) .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(withText("Johan Smith")) .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); }
/** 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); }
@Test public void testError() throws InterruptedException { when(availableStationsManager.isAvailable(any(Station.class))).thenReturn(true); doAnswer( new Answer<Object>() { private boolean first = true; @Override public Object answer(InvocationOnMock invocation) throws Throwable { Callback<StationList> callback = (Callback<StationList>) invocation.getArguments()[0]; if (first) { callback.failure(null); first = false; } else { callback.success(new StationList(new Station(0, 0, "aaaa")), null); } return null; } }) .when(parseService) .getStations(any(Callback.class)); rule.launchActivity(null); Spoon.screenshot(rule.getActivity(), "Error"); onView(withId(R.id.error_layout)).check(matches(isDisplayed())); onView(withId(R.id.retry)).perform(click()); onView(withId(R.id.error_layout)).check(matches(not(isDisplayed()))); onView(withId(R.id.total_count)).check(matches(withText("1"))); Spoon.screenshot(rule.getActivity(), "Reload_after_error"); }
@Test public void testPostRide() throws InterruptedException { // launch the main activity Intent intent = new Intent(); MainActivity mainActivity = dashBoardActivityRule.launchActivity(intent); // open the post ride activity onView(withId(R.id.buttonPostRide)).perform(click()); Thread.sleep(2000); // select source onView(withId(R.id.map)) .perform( CustomViewActions.moveToLocation( R.id.genericMapsView, sourceLatitude, sourceLongitude)); Thread.sleep(1000); onView(withId(R.id.layoutSelectSource)).perform(click()); // select destination onView(withId(R.id.map)) .perform( CustomViewActions.moveToLocation( R.id.genericMapsView, destinationLatitude, destinationLongitude)); Thread.sleep(1000); onView(withId(R.id.layoutSelectDestination)).perform(click()); // go to the next screen onView(withText(R.string.next)).perform(click()); // select date onView(withText(R.string.select_date)).perform(click()); onView(withClassName(Matchers.equalTo(DatePicker.class.getName()))) .perform(android.support.test.espresso.contrib.PickerActions.setDate(year, month, day)); onView(withText("OK")).perform(click()); // select time onView(withText(R.string.select_time)).perform(click()); onView(withClassName(Matchers.equalTo(TimePicker.class.getName()))) .perform(android.support.test.espresso.contrib.PickerActions.setTime(hour, minutes)); onView(withText("OK")).perform(click()); // details String currentTime = TimeUtils.convertToDatabaseTime(Calendar.getInstance()); onView(withHint(R.string.description)).perform(scrollTo(), replaceText(description)); onView(withHint(R.string.notes)).perform(scrollTo(), replaceText(notes)); onView(withHint(R.string.free_seats)).perform(scrollTo(), replaceText(freeSeats)); if (disabledPrefered) onView(withText(R.string.disabled_welcomed)).perform(click()); // car details onView(withHint(R.string.model)).perform(scrollTo(), replaceText(carModel)); onView(withHint(R.string.car_year)).perform(scrollTo(), replaceText(carYear)); onView(withHint(R.string.plate_numer)).perform(scrollTo(), replaceText(carplate)); // post onView(withText(R.string.post)).perform(click()); // post onView(withText(R.string.success)) .inRoot(withDecorView(not(is(mainActivity.getWindow().getDecorView())))) .check(matches(isDisplayed())); }
@Test public void selectFile() { mActivityRule.launchActivity( new MaterialFilePicker().withRequestCode(1).withHiddenFiles(true).getIntent()); }