I have an AndroidJUnit4 testcase, within this test case I'm using the following code to verify that the snackbar is displayed and contains the right text:
onView(withId(android.support.design.R.id.snackbar_text)).check(matches(isDisplayed()));
onView(allOf(withId(android.support.design.R.id.snackbar_text), withText(R.string.msg_error_unknown_user)))
.check(matches(isDisplayed()));
When I run this test on an emulator/device with API level 22, the tests run correct. When I switch to API level 17, the test fails with this exception:
android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id: com.mydomain.myappname:id/snackbar_text
Note that the application behaves in the same way on both API level; the snackbar is being displayed correctly.
Why is in my testcase the snackbar not retrieved on API level 17 and how can I fix this?