ViewActions
ViewActions simulate user interactions.
Common ViewActions
java
// Click
onView(withId(R.id.button)).perform(click());
// Long click
onView(withId(R.id.button)).perform(longClick());
// Type text and close keyboard
onView(withId(R.id.input)).perform(typeText("hello"), closeSoftKeyboard());
// Replace existing text
onView(withId(R.id.input)).perform(clearText(), typeText("new text"));
// Press IME action (e.g. Search key)
onView(withId(R.id.search)).perform(pressImeActionButton());
// Scroll to (for off-screen views)
onView(withId(R.id.bottom_view)).perform(scrollTo(), click());
// Swipe
onView(withId(R.id.view)).perform(swipeLeft());
onView(withId(R.id.view)).perform(swipeRight());
onView(withId(R.id.view)).perform(swipeUp());
// Select all text and replace
onView(withId(R.id.input)).perform(click(), pressKey(KeyEvent.KEYCODE_A, KeyEvent.META_CTRL_ON), typeText("replaced"));