以下是我的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)中的視圖是否可見或不可見。如果可見,我會假定活動已成功打開。 但它似乎沒有按照我的預期工作。 有沒有更好的方法來檢查新活動是否成功啓動,而不是檢查該活動中的視圖是否可見? 謝謝
你爲什麼不導入ViewMatchers之前叫什麼名字?'import static android.support.test.espresso.matcher.ViewMatchers。*' – Roel 2015-02-02 16:11:20
@ user2062024你可以發佈工作代碼嗎? – 2016-02-16 09:45:11
最新的Espresso將自動等待Asyntask。 – WenChao 2016-05-29 09:46:05