我目前正在尝试让 Espresso 通过它的类和它的文本来匹配 UIElement,因为它目前没有资源 ID(我知道,我知道......)。我不确定正确的语法是什么,因为 Espresso 文档很模糊(我对此和一般编程非常陌生,所以我确定我遗漏了一些东西)。这是我到目前为止所拥有的:
onView(allOf(instanceOf(android.widget.CheckBox)), withText("S"))).
perform(scrollTo()).
check(matches(isChecked()));
我试过只输入“文本框”,但在这两种情况下我都收到“预期表达式”错误。截至目前,这是识别此元素的唯一方法,因此任何指针都会有所帮助。谢谢!
最佳答案
这是我的例子:
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()));
希望对你有帮助
关于android - Espresso - 匹配一个类的实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39238744/