【问题标题】:Espresso - Matching an instance of a classEspresso - 匹配一个类的实例
【发布时间】:2016-08-30 23:52:30
【问题描述】:

我目前正试图让 Espresso 通过它的类和它的文本来匹配一个 UIElement,因为它目前没有资源 ID(我知道,我知道......)。我不确定什么是正确的语法,因为 Espresso 文档很模糊(我对这个和编程很陌生,所以我确定我错过了一些东西)。到目前为止,这是我所拥有的:

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

我尝试只输入“文本框”,但在这两种情况下,我都会收到“预期表达式”错误。到目前为止,这是识别此元素的唯一方法,因此任何指针都会有所帮助。谢谢!

【问题讨论】:

  • 试试:onView(allOf(is(instanceOf(android.widget.CheckBox)), withText("S")))
  • 我做到了。仍然收到“预期表达”消息

标签: android android-testing hamcrest android-espresso


【解决方案1】:

这是我的例子:

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()));

希望对你有帮助

【讨论】:

    猜你喜欢
    • 2019-05-17
    • 1970-01-01
    • 2018-11-02
    • 2014-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-18
    相关资源
    最近更新 更多