Android Espresso NoMatchingViewException while checking

I am testing a new Android Espresso test library. When I try:

onView(withId(R.id.gettingStarted)) 

The test runs fine. But when I try:

 onView(withId(R.id.gettingStarted)).check(matches(isDisplayed())); 

I get .NoMatchingViewException: No views in hierarchy found matching: with id: is <2131296645>

Has anyone seen anything like this before? My initial reflex is that this is just a mistake, because Espresso is only on version 1.0. I use Android Studio and follow the settings exactly.

+6
source share
3 answers

This is the expected behavior.

onView(withId(R.id.gettingStarted)) by itself does nothing. When you call the execute method, Espresso starts the mapping provided by the onView method for the current view hierarchy — if no suitable view is found, an exception is thrown.

See the Getting Started Guide for more details: https://developer.android.com/training/testing/espresso/index.html

+8
source

There are many legitimate cases where you cannot determine R.id during test development. For example, a particular species may not have R.id or R.id is not unique. This can make conventional hardware tests fragile and difficult to write because the normal way to access the view (using findViewById() ) does not work. Thus, you may need to access the private members of the Activity or Fragment that contain the view, or find a container with the famous R.id and go to its content for a specific view.

For more information: https://code.google.com/p/android-test-kit/wiki/EspressoStartGuide

0
source

This means that no view for this identifier was found in the full hierarchy of the user interface tree, regardless of whether the view is visible or invisible.

0
source

Source: https://habr.com/ru/post/956691/


All Articles