I'm currently trying to get Espresso to match a UIElement by it's class and its text since it currently does not have a resource ID (I know, I know...). I'm not sure what the proper syntax for this is since the Espresso documentation is fuzzy (I'm VERY new to this and programming in general so I'm sure I'm missing something). Here's what I have so far:
onView(allOf(instanceOf(android.widget.CheckBox)), withText("S"))).
perform(scrollTo()).
check(matches(isChecked()));
I've tried typing just "Textbox" but in both cases I get an "Expression Expected" error. As of now this is the only way to identify this element so any pointers will help. Thanks!
Espresso framework provides many view matchers. The purpose of the matcher is to match a view using different attributes of the view like Id, Text, and availability of child view. Each matcher matches a particular attributes of the view and applies to particular type of view.
Latest development (Android 9.0, API level 28 or higher) of espresso testing framework will be done in AndroidX library. testInstrumentationRunner in the android/defaultConfig sets AndroidJUnitRunner class to run the instrumentation tests.
Here' s my example:
onView(allOf(instanceOf(Toolbar.class), withChild(withText(R.string.action_settings))))
.check(matches(isDisplayed()));
so I guess that in your test would be
onView(allOf(instanceOf(android.widget.CheckBox.class)), withText("S"))).
perform(scrollTo()).
check(matches(isChecked()));
Hope it will help
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With