Espresso - Matching an instance of a class
Asked Answered
D

1

8

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!

Distinguished answered 30/8, 2016 at 23:52 Comment(2)
Try: onView(allOf(is(instanceOf(android.widget.CheckBox)), withText("S")))Barbie
I did. Still got the "Expression Expected" messageDistinguished
S
12

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

Shetrit answered 31/8, 2016 at 21:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.