Ниже приведено одно из моих тестовых примеров эспрессо.Espresso - Как проверить, запускается ли действие после выполнения определенного действия?
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())));
}
В настоящее время, что я сделал, чтобы проверить, если посмотреть на новый вид деятельности (R.id.action_logout) является visibible или нет. Если видишь, я буду считать, что активность открыта успешно. Но он не работает так, как я ожидал. Есть ли лучший способ проверить, успешно ли запущена новая активность, а не проверять вид в этом действии? Thanks
Почему вы не импортировать ViewMatchers?'import static android.support.test.espresso.matcher.ViewMatchers. *' – Roel
@ user2062024 Можете ли вы опубликовать рабочий код? –
Новый Espresso автоматически ждет Asyntask. – WenChao