【问题标题】:How to click on a button that is located on the toolbar? [closed]如何单击位于工具栏上的按钮? [关闭]
【发布时间】:2020-03-04 08:57:47
【问题描述】:

我有一个测试,我需要单击工具栏上的按钮。此按钮没有 ID,但它具有类的名称 - ImageButton。如何使用 Espresso 或 Barista 点击它? 我不能这样做,因为我没有 id

onView(...).perform(click());

尝试使用 Baristo,但这不起作用:

click(withClassName(ImageButton.class));

【问题讨论】:

    标签: android testing android-espresso barista


    【解决方案1】:

    创建一个 id 并使用机器人类并从 uitest 调用方法

    fun clicksToolbarButton(): ActivityRobot {
        onView(withId(R.id.toolbar_button))
                .perform(scrollTo(), click())
    
        return this
      }
    

    【讨论】:

    • 他们说它没有ID
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多