il seguente è uno dei miei casi di test Espresso.Espresso - Come posso verificare se un'attività viene avviata dopo aver eseguito una determinata azione?
public void testLoginAttempt() {
Espresso.onView(ViewMatchers.withId(R.id.username)).perform(ViewActions.clearText()).perform(ViewActions.typeText("[email protected]"));
Espresso.onView(ViewMatchers.withId(R.id.username)).perform(ViewActions.clearText()).perform(ViewActions.typeText("invalidpassword"));
Espresso.onView(ViewMatchers.withId(R.id.login_button)).perform(ViewActions.click());
// AFTER CLICKING THE BUTTON, A NEW ACTIVITY WILL POP UP.
// Clicking launches a new activity that shows the text entered above. You don't need to do
// anything special to handle the activity transitions. Espresso takes care of waiting for the
// new activity to be resumed and its view hierarchy to be laid out.
Espresso.onView(ViewMatchers.withId(R.id.action_logout))
.check(ViewAssertions.matches(not(ViewMatchers.isDisplayed())));
}
Attualmente quello che ho fatto è stato quello di verificare se una vista nella nuova attività (R.id.action_logout) è visibible oppure no. Se visibile, assumerò che l'attività sia stata aperta con successo. Ma non sembra funzionare come mi aspettavo. C'è un modo migliore per verificare se una nuova attività è stata lanciata correttamente invece di controllare una vista in quella attività è visibile? Grazie
Perché non si importa ViewMatchers?'Importa statico android.support.test.espresso.matcher.ViewMatchers. *' – Roel
@ user2062024 Puoi pubblicare il codice funzionante? –
L'Espresso più nuovo attende automaticamente Asyntask. – WenChao