Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Espresso - Matching an instance of a class

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!

like image 696
Los Avatar asked Aug 30 '16 23:08

Los


People also ask

What is matcher in espresso?

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.

Which is the class used in espresso framework to identify mobile test objects?

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.


1 Answers

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

like image 60
piotrek1543 Avatar answered Sep 20 '22 14:09

piotrek1543