@Test public void shouldShowsErrorIfSomethingWrongHappend() throws Exception { givenExceptionObtainingACharacter(); startActivity(); onView(allOf(withId(android.support.design.R.id.snackbar_text), withText("¯\\_(ツ)_/¯"))).check( matches(isDisplayed())); }
@Override public Matcher<View> getConstraints() { return isAssignableFrom(CameraView.class); }
public void testLoadUserHappyCaseViews() { onView(withId(R.id.rl_retry)).check(matches(not(isDisplayed()))); onView(withId(R.id.rl_progress)).check(matches(not(isDisplayed()))); onView(withId(R.id.tv_fullname)).check(matches(isDisplayed())); onView(withId(R.id.tv_email)).check(matches(isDisplayed())); onView(withId(R.id.tv_description)).check(matches(isDisplayed())); }
@Test public void testLithographyIsVisibleAndClickable() { onView(componentHostWithText(containsString("Lithography"))) .check(matches(allOf(isDisplayed(), isClickable()))); }
private void assertToastIsShown(String text) { onView(withText(text)) .inRoot(withDecorView(not(is(mActivity.getActivity().getWindow().getDecorView())))) .check(matches(isDisplayed())); } }
@Test public void clickAsyncWork() { onView(withId(R.id.async_work)).perform(click()); }
@Test public void shouldShowErrorIfSomethingWrongHappens() throws Exception { givenExceptionObtainingComicSeries(); startActivity(); onView(allOf(withId(android.support.design.R.id.snackbar_text), withText("¯\\_(ツ)_/¯"))).check( matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); }
@Test public void shouldSetAClickListenerToEveryPDFPage() throws Exception { startActivity(); openActionBarMenu(); onView(withText(R.string.menu_sample9_txt)).perform(click()); onView(withClassName(containsString(PDFViewPager.class.getSimpleName()))).perform(click()); onView(withClassName(containsString(PDFViewPager.class.getSimpleName()))).check(matches(isDisplayed())); }
@Test public void postItem() throws InterruptedException { FeedController mockFeedController = mock(FeedController.class); doNothing().when(mockFeedController).sendPostAsync("post text"); when(mComponent.feedController()).thenReturn(mockFeedController); getActivity(); onView(withId(R.id.inputText)) .perform(ViewActions.click()) .perform(ViewActions.typeText("post text")); onView(withId(R.id.fab)).perform(ViewActions.click()); ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class); verify(mockFeedController).sendPostAsync(captor.capture()); assertThat(captor.getValue(), is("post text")); onView(withId(R.id.inputText)).check(matches(withText(""))); }
@Test public void stubPick() { Instrumentation.ActivityResult result= new Instrumentation.ActivityResult(Activity.RESULT_OK, new Intent(null, ContactsContract.Contacts.CONTENT_URI)); intending(hasAction(Intent.ACTION_PICK)).respondWith(result); onView(withId(R.id.pick)).perform(click()); intended(allOf( hasAction(Intent.ACTION_PICK), hasData(ContactsContract.Contacts.CONTENT_URI))); onView(withId(R.id.view)).check(matches(isEnabled())); }
@Test public void testTreePropPropagation() { onView( componentHost( allOf(withText(containsString("root:leaf")), withTagValue(is((Object) 0))))) .check(matches(isDisplayed())); onView(componentHostWithText(containsString("root:top:bottom:leaf"))) .check(matches(isDisplayed())); onView(componentHostWithText(containsString("root:top:leaf"))).check(matches(isDisplayed())); } }
@Test public void testTakePicture() throws Exception { TakePictureIdlingResource resource = new TakePictureIdlingResource( (CameraView) rule.getActivity().findViewById(R.id.camera)); onView(withId(R.id.camera)) .perform(new AnythingAction("take picture") { @Override public void perform(UiController uiController, View view) { CameraView cameraView = (CameraView) view; cameraView.takePicture(); } }); try { registerIdlingResources(resource); onView(withId(R.id.camera)) .perform(waitFor(1000)) .check(showingPreview()); assertThat("Didn't receive valid JPEG data.", resource.receivedValidJpeg(), is(true)); } finally { unregisterIdlingResources(resource); resource.close(); } }
@Test public void sendTenDollars() { spoon.screenshot(amountActivityRule.getActivity(), "amount_empty"); onView(withText("1")).perform(click()); onView(withText("0")).perform(click()); spoon.screenshot(amountActivityRule.getActivity(), "amount_ten"); onView(withText("Send")).perform(click()); spoon.screenshot(amountActivityRule.getActivity(), "send_clicked"); }
private void navigateToMenuItem(int menuItemIdx) { onView(withContentDescription(R.string.app_name)).perform(click()); Context context = InstrumentationRegistry.getTargetContext(); if (context != null) { String menuItem = context.getResources().getStringArray(R.array.styles)[menuItemIdx]; onView(withText(menuItem)).perform(click()); } }
@Test public void testSetup() { onView(withId(R.id.camera)) .check(matches(isDisplayed())); try { onView(withId(R.id.texture_view)) .check(matches(isDisplayed())); } catch (NoMatchingViewException e) { onView(withId(R.id.surface_view)) .check(matches(isDisplayed())); } }
@Test public void cancelInManualEntryExistsActivity() { onView(withText("Force keyboard entry (bypass scan)")).perform(click()); onView(withText("Scan Credit Card using Card.io")).perform(click()); onView(withText("Card Number")).check(matches(isDisplayed())); onView(withText(LocalizedStrings.getString(StringKey.CANCEL))).perform(click()); onView(withText("Force keyboard entry (bypass scan)")).check(matches(isDisplayed())); }
@Test public void testFlash() { onView(withId(R.id.camera)) .check(new ViewAssertion() { @Override public void check(View view, NoMatchingViewException noViewFoundException) { CameraView cameraView = (CameraView) view; assertThat(cameraView.getFlash(), is(CameraView.FLASH_AUTO)); cameraView.setFlash(CameraView.FLASH_TORCH); assertThat(cameraView.getFlash(), is(CameraView.FLASH_TORCH)); } }); }
@Test public void shouldShowConnectionErrorIfHaveConnectionTroubles() throws Exception { givenConnectionExceptionObtainingComicSeries(); startActivity(); onView(allOf(withId(android.support.design.R.id.snackbar_text), withText("Connection troubles. Ask to Ironman!"))).check( matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); }