Question

I am doing automated testing using espresso. Normally if i had a message displayed I would use the resource id to locate the TextView or an element i want to test. Like this

 onView(withId(R.id.myTextViewID)).check(matches(withText(containsString("Message im checking"))));

Now the problem with crouton ALERT messages is i don't know which id to check against.

Was it helpful?

Solution

This should do the trick:

    onView(withText(containsString("Message you're checking"))).check(matches(anything()));

the matches() part already checks that the view exists in the view hierarchy. I think that's enough to check. You can replace the anything() with isDisplayed() if you want, but that check might fail if it's performed in the instant when the Crouton view has been added to the view hierarchy, but is not yet visible even partly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top