2

I want to verify that a string retrieved from a DB entry is not present anymore after the entry in DB changed, I am using following statement for this:

onView(allOf(withText("oldname"), withId(R.id.title))).check(doesNotExist());

According to the espresso documentation and other posts I saw this should work, but I am getting following error:

android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: (with text: is "oldname" and with id: com.myco.myapp:id/apkName)
David
  • 3,971
  • 1
  • 26
  • 65

1 Answers1

1

The problem is that you're looking for a View with the text "oldname" and then trying to assert that it doesn't exist, but this doesn't work because the View doesn't exist (so you can't assert anything on it).

Where you go from here depends on exactly what you're trying to accomplish. If the view should not be there at all:

onView(withId(R.id.title)).check(doesNotExist());

If the view should be there, but without that text:

onView(allOf(not(withText("oldname")),withId(R.id.title))).check(matches(isDisplayed());

Or a variation of that:

onView(withId(R.id.title)).check(matches(not(withText("oldName"))));

The first variation says "make sure that there's a view with that id and not that text". The second variation says "make sure that the view with that id doesn't have that text".

Jeremy Figgins
  • 113
  • 1
  • 8
  • Thanks, very clarifying, only thing, it is a list where I have multiple list items, so each list item would have the id present, but different texts, not sure above approaches would work for that case. – David Oct 08 '18 at 14:20
  • Or asking in another way, in which case would check(doesNotExist()); do work? I mean the check is for verify that a view does not exist? – David Oct 08 '18 at 14:25
  • Assuming there is an adapter attached to the view, then this answer seems related: https://stackoverflow.com/a/21175076/2711811. –  Oct 09 '18 at 16:42