Java Code Examples for android.support.test.espresso.NoMatchingViewException

The following are top voted examples for showing how to use android.support.test.espresso.NoMatchingViewException. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: polling-station-app   File: TestElectionChoice.java   Source Code and License 7 votes vote down vote up
@Test
    public void searchCityAndClick() throws Exception {
        List<Election> unfilteredList = electionActivity.getAdapter().getList();

        onView(withId(R.id.search)).perform(click());

        final Election toClick = unfilteredList.get(0);
        onView(withId(android.support.design.R.id.search_src_text)).perform(typeText(toClick.getPlace()));

        onView (withId (R.id.election_list)).check (ViewAssertions.matches (new Matchers().withListSize (1)));

        onData(instanceOf(Election.class))
                .inAdapterView(withId(R.id.election_list))
                .atPosition(0)
                .perform(click());
//        intended(hasComponent(MainActivity.class.getName()));
        onView(withId(R.id.app_bar)).check(new ViewAssertion() {
            @Override
            public void check(View view, NoMatchingViewException noViewFoundException) {
                assertEquals(((Toolbar) view).getTitle(), toClick.getKind());
                assertEquals(((Toolbar) view).getSubtitle(), toClick.getPlace());
            }
        });
    }
 
Example 2
Project: GitHub   File: ConnectbotMatchers.java   Source Code and License 6 votes vote down vote up
@NonNull
public static ViewAssertion hasHolderItem(final Matcher<RecyclerView.ViewHolder> viewHolderMatcher) {
	return new ViewAssertion() {
		@Override public void check(View view, NoMatchingViewException e) {
			if (!(view instanceof RecyclerView)) {
				throw e;
			}

			boolean hasMatch = false;
			RecyclerView rv = (RecyclerView) view;
			for (int i = 0; i < rv.getChildCount(); i++) {
				RecyclerView.ViewHolder vh = rv.findViewHolderForAdapterPosition(i);
				hasMatch |= viewHolderMatcher.matches(vh);
			}
			Assert.assertTrue(hasMatch);
		}
	};
}
 
Example 3
Project: PXLSRT   File: CameraViewTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testAutoFocus() {
    onView(withId(R.id.camera))
            .check(new ViewAssertion() {
                @Override
                public void check(View view, NoMatchingViewException noViewFoundException) {
                    CameraView cameraView = (CameraView) view;
                    // This can fail on devices without auto-focus support
                    assertThat(cameraView.getAutoFocus(), is(true));
                    cameraView.setAutoFocus(false);
                    assertThat(cameraView.getAutoFocus(), is(false));
                    cameraView.setAutoFocus(true);
                    assertThat(cameraView.getAutoFocus(), is(true));
                }
            });
}
 
Example 4
Project: PXLSRT   File: CameraViewTest.java   Source Code and License 6 votes vote down vote up
private static ViewAssertion showingPreview() {
    return new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException noViewFoundException) {
            if (android.os.Build.VERSION.SDK_INT < 14) {
                return;
            }
            CameraView cameraView = (CameraView) view;
            TextureView textureView = (TextureView) cameraView.findViewById(R.id.texture_view);
            Bitmap bitmap = textureView.getBitmap();
            int topLeft = bitmap.getPixel(0, 0);
            int center = bitmap.getPixel(bitmap.getWidth() / 2, bitmap.getHeight() / 2);
            int bottomRight = bitmap.getPixel(
                    bitmap.getWidth() - 1, bitmap.getHeight() - 1);
            assertFalse("Preview possibly blank: " + Integer.toHexString(topLeft),
                    topLeft == center && center == bottomRight);
        }
    };
}
 
Example 5
Project: ChimpCheck   File: Performer.java   Source Code and License 6 votes vote down vote up
public Act performAction(Act origin) throws NoViewEnabledException {

        Act performedAction = null;

        for(ViewManager.ViewTarget target: getTargets(origin)) {
             try {
                 performedAction = performAction(origin, target);
                 if (performedAction != null) {
                     return performedAction;
                 }
             } catch (NoMatchingViewException e) {
                 Log.i(tag("performAction"),"Attempted " + target.toString() + " and failed: " + e.toString());
             }
        }

        Log.e(tag("performAction"),"Exhausted all action targets.");

        throw new NoViewEnabledException(tag("performAction") + ": exhausted all action targets");

    }
 
Example 6
Project: polling-station-app   File: TestElectionChoice.java   Source Code and License 6 votes vote down vote up
@Test
    public void clickOnElection() throws Exception {
        final Election e = electionActivity.getAdapter().getItem(1);

        onData(instanceOf(Election.class)) // We are using the position so don't need to specify a data matcher
                .inAdapterView(withId(R.id.election_list)) // Specify the explicit id of the ListView
                .atPosition(1) // Explicitly specify the adapter item to use
                .perform(click());
//        intended(hasComponent(MainActivity.class.getName()));
        onView(withId(R.id.app_bar)).check(new ViewAssertion() {
            @Override
            public void check(View view, NoMatchingViewException noViewFoundException) {
                assertEquals(((Toolbar) view).getTitle(), e.getKind());
                assertEquals(((Toolbar) view).getSubtitle(), e.getPlace());
            }
        });
    }
 
Example 7
Project: smart-lens   File: BaseActivityTest.java   Source Code and License 6 votes vote down vote up
@Test
public void checkToolbar() throws Exception {
    //Test with the string title
    mTestActivity.runOnUiThread(() -> mTestActivity.setToolbar(R.id.toolbar, ACTIVITY_TITLE, true));
    CustomMatchers.matchToolbarTitle(ACTIVITY_TITLE).check(matches(isDisplayed()));
    Espresso.onView(withContentDescription("Navigate up")).check(matches(isDisplayed()));

    //Test with the string resource title
    mTestActivity.runOnUiThread(() -> mTestActivity.setToolbar(R.id.toolbar, R.string.app_name, true));
    CustomMatchers.matchToolbarTitle(mTestActivity.getString(R.string.app_name)).check(matches(isDisplayed()));
    Espresso.onView(withContentDescription("Navigate up")).check(matches(isDisplayed()));

    //Hide home button
    mTestActivity.runOnUiThread(() -> mTestActivity.setToolbar(R.id.toolbar, ACTIVITY_TITLE, false));
    try {
        Espresso.onView(withContentDescription("Navigate up")).perform(click());
        Assert.fail();
    } catch (NoMatchingViewException e) {
        //Pass
    }
}
 
Example 8
Project: ZeroKit-Android-SDK   File: SampleAppTest.java   Source Code and License 6 votes vote down vote up
private String encrypt(String text) throws InterruptedException {
    final String[] result = new String[1];

    onView(withId(R.id.editText4)).perform(scrollTo(), replaceText(text), closeSoftKeyboard());
    onView(allOf(withId(R.id.button2), withText("Encrypt"))).perform(scrollTo(), click());
    onView(withId(R.id.editText5)).check(new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException noViewFoundException) {
            result[0] = String.valueOf(((EditText) view).getText());
        }
    });
    onView(allOf(withId(R.id.button3), withText("Test Decrypt"))).perform(scrollTo(), click());
    onView(withId(R.id.textView5)).check(matches(withText(text)));
    onView(allOf(withId(R.id.button4), withText("Copy"))).perform(scrollTo(), click());

    return result[0];
}
 
Example 9
Project: Goalie_Android   File: FriendActivityInstrumentedTest.java   Source Code and License 6 votes vote down vote up
@Test
public void addContact() throws Exception {
    onView(withId(R.id.action_add_friends)).perform(click());
    onView(withId(R.id.add_username)).check(matches(isDisplayed()));

    onView(withId(R.id.add_username)).perform(clearText(), typeText("tes"));
    onView(withText(mActivityRule.getActivity().getString(R.string.add))).perform(click());
    onView(withId(R.id.add_friend_status)).check(matches(isDisplayed()));

    onView(withText(mActivityRule.getActivity().getString(R.string.cancel))).perform(click());
    // expecting to fail as view doesn't exist
    try {
        onView(withId(R.id.add_username)).check(matches(isDisplayed()));
    } catch (NoMatchingViewException e) {
        return;
    }
    assertTrue(false);
}
 
Example 10
Project: ZeroKit-Android-Sample   File: SampleAppTest.java   Source Code and License 6 votes vote down vote up
private String encrypt(String text) throws InterruptedException {
    final String[] result = new String[1];

    onView(withId(R.id.editText4)).perform(scrollTo(), replaceText(text), closeSoftKeyboard());
    onView(allOf(withId(R.id.button2), withText("Encrypt"))).perform(scrollTo(), click());
    onView(withId(R.id.editText5)).check(new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException noViewFoundException) {
            result[0] = String.valueOf(((EditText) view).getText());
        }
    });
    onView(allOf(withId(R.id.button3), withText("Test Decrypt"))).perform(scrollTo(), click());
    onView(withId(R.id.textView5)).check(matches(withText(text)));
    onView(allOf(withId(R.id.button4), withText("Copy"))).perform(scrollTo(), click());

    return result[0];
}
 
Example 11
Project: delern   File: DeckOperationsTest.java   Source Code and License 6 votes vote down vote up
@Test
public void noDecksMessageShown() {
    waitView(() -> onView(withId(R.id.fab)).check(matches(isDisplayed())));

    // Delete all existing decks.
    try {
        while (true) {
            onView(first(withId(R.id.deck_popup_menu))).perform(click());
            deleteSelectedDeck();
        }
    } catch (NoMatchingViewException e) {
        // Finished deleting all decks.
    }

    waitView(() -> onView(allOf(withId(R.id.empty_recyclerview_message),
            withText(R.string.empty_decks_message))).check(matches(isDisplayed())));
}
 
Example 12
Project: espresso-macchiato   File: EspRecyclerViewItem.java   Source Code and License 6 votes vote down vote up
/**
 * Check that this item exist.
 *
 * Is true when adapter has matching item ignores the display state.
 *
 * @since Espresso Macchiato 0.6
 */

public void assertExist() {
    findRecyclerView().check(new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException noViewFoundException) {
            if (noViewFoundException != null) {
                throw noViewFoundException;
            }

            RecyclerView recyclerView = (RecyclerView) view;
            if (index >= recyclerView.getAdapter().getItemCount()) {
                throw new AssertionFailedError("Requested item should exist.");
            }
        }
    });
}
 
Example 13
Project: espresso-macchiato   File: GridLayoutManagerColumnCountAssertion.java   Source Code and License 6 votes vote down vote up
@Override
public void check(View view, NoMatchingViewException noViewFoundException) {
    if (noViewFoundException != null) {
        throw noViewFoundException;
    }

    RecyclerView recyclerView = (RecyclerView) view;
    if (recyclerView.getLayoutManager() instanceof GridLayoutManager) {
        GridLayoutManager gridLayoutManager = (GridLayoutManager) recyclerView.getLayoutManager();
        int spanCount = gridLayoutManager.getSpanCount();
        if (spanCount != expectedColumnCount) {
            String errorMessage = "expected column count " + expectedColumnCount
                    + " but was " + spanCount;
            throw new AssertionError(errorMessage);
        }
    } else {
        throw new IllegalStateException("no grid layout manager");
    }
}
 
Example 14
Project: espresso-macchiato   File: LayoutManagerItemVisibilityAssertion.java   Source Code and License 6 votes vote down vote up
@Override
public void check(View view, NoMatchingViewException noViewFoundException) {
    if (noViewFoundException != null) {
        throw noViewFoundException;
    }

    RecyclerView recyclerView = (RecyclerView) view;
    if (recyclerView.getLayoutManager() instanceof LinearLayoutManager) {
        LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
        int firstVisibleItem = layoutManager.findFirstVisibleItemPosition();
        int lastVisibleItem = layoutManager.findLastVisibleItemPosition();

        boolean indexInRange = firstVisibleItem <= index && index <= lastVisibleItem;
        if ((shouldBeVisible && !indexInRange) || (!shouldBeVisible && indexInRange)) {
            String errorMessage = "expected item " + index + " to " +
                    (shouldBeVisible ? "" : "not") + " be visible, but was" +
                    (indexInRange ? "" : " not") + " visible";
            throw new AssertionError(errorMessage);

        }
    }
}
 
Example 15
Project: SimpleCamera   File: CameraViewTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testAutoFocus() {
    onView(withId(com.google.android.cameraview.test.R.id.camera))
            .check(new ViewAssertion() {
                @Override
                public void check(View view, NoMatchingViewException noViewFoundException) {
                    CameraView cameraView = (CameraView) view;
                    // This can fail on devices without auto-focus support
                    assertThat(cameraView.getAutoFocus(), is(true));
                    cameraView.setAutoFocus(false);
                    assertThat(cameraView.getAutoFocus(), is(false));
                    cameraView.setAutoFocus(true);
                    assertThat(cameraView.getAutoFocus(), is(true));
                }
            });
}
 
Example 16
Project: SimpleCamera   File: CameraViewTest.java   Source Code and License 6 votes vote down vote up
private static ViewAssertion showingPreview() {
    return new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException noViewFoundException) {
            if (android.os.Build.VERSION.SDK_INT < 14) {
                return;
            }
            CameraView cameraView = (CameraView) view;
            TextureView textureView = (TextureView) cameraView.findViewById(com.google.android.cameraview.test.R.id.texture_view);
            Bitmap bitmap = textureView.getBitmap();
            int topLeft = bitmap.getPixel(0, 0);
            int center = bitmap.getPixel(bitmap.getWidth() / 2, bitmap.getHeight() / 2);
            int bottomRight = bitmap.getPixel(
                    bitmap.getWidth() - 1, bitmap.getHeight() - 1);
            assertFalse("Preview possibly blank: " + Integer.toHexString(topLeft),
                    topLeft == center && center == bottomRight);
        }
    };
}
 
Example 17
Project: material-components-android   File: BottomSheetBehaviorTouchTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testTouchCoordinatorLayout() {
  final CoordinatorLayoutActivity activity = activityTestRule.getActivity();
  down = false;
  Espresso.onView(sameInstance((View) activity.mCoordinatorLayout))
      .perform(ViewActions.click()) // Click outside the bottom sheet
      .check(
          new ViewAssertion() {
            @Override
            public void check(View view, NoMatchingViewException e) {
              assertThat(e, is(nullValue()));
              assertThat(view, is(notNullValue()));
              // Check that the touch event fell through to the container
              assertThat(down, is(true));
            }
          });
}
 
Example 18
Project: DebugRank   File: Util.java   Source Code and License 6 votes vote down vote up
public static ViewAssertion flexGridHasCode(final List<CodeLine> expectedCodeLines)
{
    return new ViewAssertion()
    {
        @Override
        public void check(View view, NoMatchingViewException noViewException)
        {
            FlexGrid flexGrid = (FlexGrid) view;

            List<CodeLine> actualCodeLines = (List<CodeLine>) flexGrid.getItemsSource();

            for (int i = 0; i < expectedCodeLines.size(); i++)
            {
                CodeLine expected = expectedCodeLines.get(i);
                CodeLine actual = actualCodeLines.get(i);

                assertEquals(expected.getCodeText(), actual.getCodeText());
            }
        }
    };
}
 
Example 19
Project: cameraview   File: CameraViewTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testAutoFocus() {
    onView(withId(R.id.camera))
            .check(new ViewAssertion() {
                @Override
                public void check(View view, NoMatchingViewException noViewFoundException) {
                    CameraView cameraView = (CameraView) view;
                    // This can fail on devices without auto-focus support
                    assertThat(cameraView.getAutoFocus(), is(true));
                    cameraView.setAutoFocus(false);
                    assertThat(cameraView.getAutoFocus(), is(false));
                    cameraView.setAutoFocus(true);
                    assertThat(cameraView.getAutoFocus(), is(true));
                }
            });
}
 
Example 20
Project: cameraview   File: CameraViewTest.java   Source Code and License 6 votes vote down vote up
private static ViewAssertion showingPreview() {
    return new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException noViewFoundException) {
            if (android.os.Build.VERSION.SDK_INT < 14) {
                return;
            }
            CameraView cameraView = (CameraView) view;
            TextureView textureView = (TextureView) cameraView.findViewById(R.id.texture_view);
            Bitmap bitmap = textureView.getBitmap();
            int topLeft = bitmap.getPixel(0, 0);
            int center = bitmap.getPixel(bitmap.getWidth() / 2, bitmap.getHeight() / 2);
            int bottomRight = bitmap.getPixel(
                    bitmap.getWidth() - 1, bitmap.getHeight() - 1);
            assertFalse("Preview possibly blank: " + Integer.toHexString(topLeft),
                    topLeft == center && center == bottomRight);
        }
    };
}
 
Example 21
Project: EDSApp   File: SDKTestUtils.java   Source Code and License 6 votes vote down vote up
public static void fillCompulsorySurvey(int numQuestions, String optionValue) {
    //when: answer NO to every question
    //Wait for fragment load data from SurveyService
    IdlingResource idlingResource=null;
    onView(withTagValue(Matchers.is((Object) getActivityInstance().getApplicationContext().getString(R.string.tab_tag_assess)))).perform(click());
    for (int i = 0; i < numQuestions; i++) {
        try {
            idlingResource = new ElapsedTimeIdlingResource(1 * 1000);
            Espresso.registerIdlingResources(idlingResource);
            onData(is(instanceOf(Question.class)))
                    .inAdapterView(withId(R.id.listView))
                    .atPosition(i)
                    .onChildView(withId(R.id.answer)).onChildView(withText(optionValue))
                    .perform(click());
        } catch (NoMatchingViewException e) {
            Log.e(TAG,"Exception selecting option value " + optionValue);
        }
        finally {
            Espresso.unregisterIdlingResources(idlingResource);
        }
    }
}
 
Example 22
Project: 301p   File: BrowseFriendInventoryUITest.java   Source Code and License 6 votes vote down vote up
/**
 * UC3.1.2 BrowseFriendGeneralSearch
 * Precondition User exists with friends that have inventories,
 * with both private and public items.
 */
@Test
public void testBrowseFriendGeneral() throws Exception {
    /**
     * Navigate to FriendList and Find Friend
     */


    /**
     * Checks that there are two items from the filtered friend
     */
    onView(withText("testItem1f1")).check(matches(isDisplayed()));
    onView(withText("testItem2f1")).check(matches(isDisplayed()));
    try {
        onView(withText("testItem3f1")).check(matches(isDisplayed()));
        fail("View should not be displayed");
    } catch (NoMatchingViewException e) {
        //pass
    }

}
 
Example 23
Project: 301p   File: BrowseInventoryUITest.java   Source Code and License 6 votes vote down vote up
/**
     * Testing the browse test.
     *
     * @throws Exception
     */
    @Test
    public void testSimpleBrowseSearch() throws Exception {


        onView(withText("testItem1f1")).check(matches(isDisplayed()));
        onView(withText("testItem2f1")).check(matches(isDisplayed()));
        try {
            onView(withText("testItem2f4")).check(matches(isDisplayed()));
            fail("View should not be displayed");
        } catch (NoMatchingViewException e) {
            //pass
        }
//        onData(hasToString("testItem1f1"))
//                .inAdapterView(withId(R.id.BrowseListView)).atPosition(0).onChildView(withId(R.id.tileViewItemName))
//                .check(matches(isDisplayed()));

    }
 
Example 24
Project: zulip-android   File: ViewAssertions.java   Source Code and License 6 votes vote down vote up
public static ViewAssertion checkMessagesOnlyFromToday() {
    return new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException e) {
            if (!(view instanceof RecyclerView)) {
                throw e;
            }
            RecyclerView rv = (RecyclerView) view;
            RecyclerMessageAdapter recyclerMessageAdapter = (RecyclerMessageAdapter) rv.getAdapter();
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("OfDate-" + (new Date()).toString() + " { ");
            for (int index = 0; index < recyclerMessageAdapter.getItemCount(); index++) {
                if (recyclerMessageAdapter.getItem(index) instanceof Message) {
                    Message message = (Message) recyclerMessageAdapter.getItem(index);
                    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm", Locale.US);
                    stringBuilder.append(message.getID() + "-" + sdf.format(message.getTimestamp()) + " , ");
                    assertTrue("This message is not of today ID=" + message.getID() + ":" + message.getIdForHolder() + "\ncontent=" + message.getContent(), DateUtils.isToday(message.getTimestamp().getTime()));
                }
            }
            stringBuilder.append(" }");
            printLogInPartsIfExceeded(stringBuilder, "checkMessagesOnlyFromToday");
        }
    };
}
 
Example 25
Project: android-step-by-step   File: EspressoTools.java   Source Code and License 6 votes vote down vote up
public static ViewAssertion hasViewWithTextAtPosition(final int index, final CharSequence text) {
    return new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException e) {
            if (!(view instanceof RecyclerView)) {
                throw e;
            }
            RecyclerView rv = (RecyclerView) view;
            ArrayList<View> outviews = new ArrayList<>();
            rv.findViewHolderForAdapterPosition(index).itemView.findViewsWithText(outviews, text,
                    FIND_VIEWS_WITH_TEXT);
            Truth.assert_().withFailureMessage("There's no view at index " + index + " of recyclerview that has text : " + text)
                    .that(outviews).isNotEmpty();
        }
    };
}
 
Example 26
Project: android-step-by-step   File: EspressoTools.java   Source Code and License 6 votes vote down vote up
public static ViewAssertion doesntHaveViewWithText(final String text) {
    return new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException e) {
            if (!(view instanceof RecyclerView)) {
                throw e;
            }
            RecyclerView rv = (RecyclerView) view;
            ArrayList<View> outviews = new ArrayList<>();
            for (int index = 0; index < rv.getAdapter().getItemCount(); index++) {
                rv.findViewHolderForAdapterPosition(index).itemView.findViewsWithText(outviews, text,
                        FIND_VIEWS_WITH_TEXT);
                if (outviews.size() > 0) break;
            }
            Truth.assertThat(outviews).isEmpty();
        }
    };
}
 
Example 27
Project: malariapp   File: SDKTestUtils.java   Source Code and License 6 votes vote down vote up
public static void fillCompulsorySurvey(int numQuestions, String optionValue) {
    //when: answer NO to every question
    //Wait for fragment load data from SurveyService
    IdlingResource idlingResource=null;
    onView(withTagValue(Matchers.is((Object) getActivityInstance().getApplicationContext().getString(R.string.tab_tag_assess)))).perform(click());
    for (int i = 0; i < numQuestions; i++) {
        try {
            idlingResource = new ElapsedTimeIdlingResource(1 * 1000);
            Espresso.registerIdlingResources(idlingResource);
            onData(is(instanceOf(Question.class)))
                    .inAdapterView(withId(R.id.listView))
                    .atPosition(i)
                    .onChildView(withId(R.id.answer)).onChildView(withText(optionValue))
                    .perform(click());
        } catch (NoMatchingViewException e) {
            Log.e(TAG,"Exception selecting option value " + optionValue);
        }
        finally {
            Espresso.unregisterIdlingResources(idlingResource);
        }
    }
}
 
Example 28
Project: Bill-Calculator   File: RecyclerViewInteraction.java   Source Code and License 6 votes vote down vote up
public RecyclerViewInteraction checkView(final @IdRes int id, final ViewAssertion itemViewAssertion) {
    viewInteraction.check(new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException ex) {
            RecyclerView recyclerView = (RecyclerView) view;
            RecyclerView.ViewHolder viewHolderForPosition = recyclerView.findViewHolderForLayoutPosition(position);
            if (viewHolderForPosition == null) {
                throw (new PerformException.Builder())
                        .withActionDescription(toString())
                        .withViewDescription(HumanReadables.describe(view))
                        .withCause(new IllegalStateException("No view holder at position: " + position))
                        .build();
            } else {
                View viewAtPosition = viewHolderForPosition.itemView.findViewById(id);
                itemViewAssertion.check(viewAtPosition, ex);
            }
        }
    });
    return this;
}
 
Example 29
Project: DiscogsBrowser   File: TestUtils.java   Source Code and License 5 votes vote down vote up
@Override
public void check(View view, NoMatchingViewException noViewFoundException)
{
    if (noViewFoundException != null)
        throw noViewFoundException;

    assertEquals(((EditText) view).getText().toString(), searchTerm);
}
 
Example 30
Project: DiscogsBrowser   File: RecyclerViewSizeAssertion.java   Source Code and License 5 votes vote down vote up
@Override
public void check(View view, NoMatchingViewException noViewFoundException)
{
    if (noViewFoundException != null)
        throw noViewFoundException;

    RecyclerView.Adapter adapter = ((MyRecyclerView) view).getAdapter();
    assertEquals(adapter.getItemCount(), wantedSize);
}
 
Example 31
Project: adyen-android   File: EspressoTestUtils.java   Source Code and License 5 votes vote down vote up
private static void waitForText(final String text, final long sleepInterval, final long timeout)
        throws InterruptedException, TimeoutException {
    final long currentTime = System.currentTimeMillis();
    final long timeoutTime = currentTime + timeout;
    while (System.currentTimeMillis() < timeoutTime) {
        try {
            onView(withText(text)).check(matches(isDisplayed()));
            return;
        } catch (final NoMatchingViewException exception) {
            // Don't do anything. Keep waiting till timeout.
        }
        Thread.sleep(sleepInterval);
    }
    throw new TimeoutException("View with text " + text + " could not be found.");
}
 
Example 32
Project: android-training-2017   File: CalculatorAndroidTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testActivityRun() {
    calculatorActivity.launchActivity(new Intent());

    ViewInteraction calculateButton = onView(withId(R.id.calculate_button));
    calculateButton.check(matches(isDisplayed()));
    calculateButton.check(new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException noViewFoundException) {
            if(view.isEnabled()) {
                throw new IllegalStateException("button enabled");
            }
        }
    });

    onView(withId(R.id.input_field_edit_text)).perform(typeText("1+2"));

    calculateButton.check(matches(isEnabled()));

    calculateButton.perform(click());

    /*onView(withId(R.id.result_text_view)).check(new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException noViewFoundException) {
            if(!((TextView)view).getText().toString().equals("3")) {
                throw new IllegalStateException("result wrong. Aspected 3");
            }
        }
    });*/

}
 
Example 33
Project: PXLSRT   File: CameraViewTest.java   Source Code and License 5 votes vote down vote up
@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()));
    }
}
 
Example 34
Project: PXLSRT   File: CameraViewTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testFacing() {
    onView(withId(R.id.camera))
            .check(new ViewAssertion() {
                @Override
                public void check(View view, NoMatchingViewException noViewFoundException) {
                    CameraView cameraView = (CameraView) view;
                    assertThat(cameraView.getFacing(), is(CameraView.FACING_BACK));
                    cameraView.setFacing(CameraView.FACING_FRONT);
                    assertThat(cameraView.getFacing(), is(CameraView.FACING_FRONT));
                }
            })
            .perform(waitFor(1000))
            .check(showingPreview());
}
 
Example 35
Project: PXLSRT   File: CameraViewTest.java   Source Code and License 5 votes vote down vote up
@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));
                }
            });
}
 
Example 36
Project: ChimpCheck   File: Performer.java   Source Code and License 5 votes vote down vote up
public Act performWildCardAction(Act origin) {

        Espresso.onView(isRoot()).perform( new ChimpStagingAction() );

        chimpDriver.preemptiveTraceReport();

        try {
            ArrayList<UiObject2> uiObject2s = wildCardManager.retrieveUiObject2s(wildCardSelector, wildCardChildSelector, 10);
            ArrayList<WildCardTarget> matchers = MatcherManager.getViewMatchers(uiObject2s, userDefinedMatcher);

            while(matchers.size() > 0) {
                Log.i(tag("wildcard"), Integer.toString(matchers.size()));
                WildCardTarget target = wildCardManager.popOne(matchers);
                try {
                    Log.i(tag("wildcard"), "Attempting to perform action on UiObject");
                    Act result = performWildCardTargetAction(origin, target);
                    return result;
                } catch (AmbiguousViewMatcherException avme){
                    Log.e(tag("wildcard"), avme.toString());
                } catch (NoMatchingViewException nmve){
                    Log.e(tag("wildcard"), nmve.toString());
                } catch (PerformException pe){
                    Log.e(tag("wildcard"), pe.toString());

                }
            }

        } catch (Exception ee) {
            Log.e(tag("wildcard"), "Error occurred at wild card top-level");
            ee.printStackTrace();
        }

        Log.e(tag("wildcard"), "Exhausted all wild card options.");
        return null;

    }
 
Example 37
Project: ChimpCheck   File: EspressoChimpDriver.java   Source Code and License 5 votes vote down vote up
@Override
protected EventTraceOuterClass.TryEvent launchTryEvent(EventTraceOuterClass.TryEvent tryEvent)
throws MalformedBuiltinPredicateException, ReflectionPredicateException, PropertyViolatedException {
    Log.i(runner.chimpTag("[email protected]"), tryEvent.toString());

    try {
        EventTraceOuterClass.TryEvent.TryType tryType = tryEvent.getTryType();
        switch (tryType) {
            case APPEVENT: executeEvent( tryEvent.getAppEvent() ); break;
            case EXTEVENT: executeEvent( tryEvent.getExtEvent() ); break;
            case TRACE:
                for (EventTraceOuterClass.UIEvent uiEvent : tryEvent.getTrace().getEventsList()) {
                    executeEvent( uiEvent );
                }
                break;
        }
    } catch (NoViewEnabledException e) {
        Log.i(runner.chimpTag("[email protected]"), e.toString());
    } catch (NoMatchingViewException nm){
        Log.i(runner.chimpTag("[email protected]"), nm.toString());
    }
    /* Probably more catching here to do. Find out what Espresso throws when the view you click is not there.
    // Exception: android.support.test.espresso.NoMatchingViewException:
     catch (NoMatchingViewException e) { }
    */

    return tryEvent;
}
 
Example 38
Project: lacomida   File: RecyclerViewItemCountAssertion.java   Source Code and License 5 votes vote down vote up
@Override
public void check(View view, NoMatchingViewException noMatchingViewException) {
	if (noMatchingViewException != null) {
		throw noMatchingViewException;
	}
	RecyclerView recyclerView = (RecyclerView) view;
	RecyclerView.Adapter adapter = recyclerView.getAdapter();
	assertEquals(expected, adapter.getItemCount());
}
 
Example 39
Project: polling-station-app   File: TestElectionChoice.java   Source Code and License 5 votes vote down vote up
@Test
public void atElectionActivity() throws Exception {
    onView(withId(R.id.app_bar)).check(new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException noViewFoundException) {
            assertEquals(((Toolbar) view).getTitle(), "Choose election");
        }
    });
}
 
Example 40
Project: FireBaseTest   File: RecyclerViewItemCountAssertion.java   Source Code and License 5 votes vote down vote up
@Override
public void check(View view, NoMatchingViewException noViewFoundException) {
    if (noViewFoundException != null) {
        throw noViewFoundException;
    }

    RecyclerView recyclerView = (RecyclerView) view;
    RecyclerView.Adapter adapter = recyclerView.getAdapter();
    assertThat(adapter.getItemCount(), matcher);
}