Android Testing UI with Espresso Performing an action on a view

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

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:

ViewActions.click()
ViewActions.typeText()
ViewActions.clearText()

For example, to click on the view:

onView(...).perform(click());
onView(withId(R.id.button_simple)).perform(click());

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


Got any Android Question?