class LoginRobot { LoginRobot username(String username) { onView(withId(R.id.login_username)).perform(typeText(username), closeSoftKeyboard()); return this; } LoginRobot password(String password) { onView(withId(R.id.login_password)).perform(typeText(password), closeSoftKeyboard()); return this; } ResultLoginRobot login() { Intents.init(); Matcher<Intent> matcher = hasComponent(MainActivity.class.getName()); onView(withId(R.id.login_button)).perform(scrollTo(), click()); return new ResultLoginRobot(); } } class ResultLoginRobot { ResultRobot isSuccess() { onView(withId(R.id.login_button)).perform(click()); intended(matcher); Intents.release(); } }