Android Testing UI with Espresso Performing an action on a view


It is possible to perform ViewActions on a view using the perform method.
The ViewActions class provides helper methods for the most common actions, like:

For example, to click on the view:


You can execute more than one action with one perform call:

onView(...).perform(typeText("Hello"), click());

If the view you are working with is located inside a ScrollView (vertical or horizontal), consider preceding actions that require the view to be displayed (like click() and typeText()) with scrollTo(). This ensures that the view is displayed before proceeding to the other action:

onView(...).perform(scrollTo(), click());