Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Espresso - TextView contains String

Quite simply, how do I say if a given TextView contains a specific string in Espresso.

The equivalent of: myStrings.contains("Subby");

like image 858
Subby Avatar asked May 12 '17 09:05

Subby


People also ask

How do I get TextView espresso from text?

The basic idea is to use a method with an internal ViewAction that retrieves the text in its perform method. Anonymous classes can only access final fields, so we cannot just let it set a local variable of getText() , but instead an array of String is used to get the string out of the ViewAction .

How do you check espresso text?

Verify the TextView textonView(withId(R. id. text_simple)). check(matches(withText("Hello Espresso!")))


1 Answers

You can use the Hamcrest library. It has a method containsString. I believe it is in the Espresso library.

You can static import it in your class:

import static org.hamcrest.core.StringContains.containsString; 

Use containsString in your method on a TextView:

textView.check(matches(withText(containsString("Test")))); 
like image 70
476rick Avatar answered Oct 18 '22 02:10

476rick