2016-08-30 127 views
2

我目前正在尝试通过它的类和它的文本来获得Espresso来匹配UIElement,因为它当前没有资源ID(我知道,我知道...)。我不确定这是什么正确的语法,因为Espresso文档是模糊的(我对这一点和编程一般都很陌生,所以我确信我错过了一些东西)。这是我到目前为止有:咖啡 - 匹配一个类的实例

onView(allOf(instanceOf(android.widget.CheckBox)), withText("S"))). 
       perform(scrollTo()). 
       check(matches(isChecked())); 

我试过打字只是“文本框”,但在这两种情况下,我得到错误的“预期的表达”。到目前为止,这是识别这个元素的唯一方法,所以任何指针都会有帮助。谢谢!

+0

尝试:onView(allOf(是(}这种( android.widget.CheckBox)),withText(“S”))) – jeprubio

+0

我做到了。仍然得到了“预期表达”的消息 – Los

回答

2

这是我的例子:

onView(allOf(instanceOf(Toolbar.class), withChild(withText(R.string.action_settings)))) 
.check(matches(isDisplayed())); 

,所以我想在您的测试将是

onView(allOf(instanceOf(android.widget.CheckBox.class)), withText("S"))). 
       perform(scrollTo()). 
       check(matches(isChecked())); 

希望这将有助于