androidtestingandroid-espressobarista

How to click on a button that is located on the toolbar?


I have a test in which I need to click on the button located on the toolbar. This button does not have an ID, but it has the name of the class - ImageButton. How can I click on it using Espresso or Barista? I can not do this because I do not have id

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

Trying to use Baristo, but this does not work:

click(withClassName(ImageButton.class));

Solution

  • Create an id and use a robot class and invoke the method from uitest

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