Espresso - How can I check if an activity is launched after performing a certain action?

后端 未结 8 1531
北海茫月
北海茫月 2020-12-02 15:34

the following is one of my Espresso test cases.

    public void testLoginAttempt() {
        Espresso.onView(ViewMatchers.withId(R.id.username)).perform(View         


        
8条回答
  •  南方客
    南方客 (楼主)
    2020-12-02 16:04

    You may do it as follows:

        @Test
    public void testLoginAttempt() {
        Espresso.onView(ViewMatchers.withId(R.id.username)).perform(ViewActions.clearText()).perform(ViewActions.typeText("nonexistinguser@example.com"));
        Espresso.onView(ViewMatchers.withId(R.id.username)).perform(ViewActions.clearText()).perform(ViewActions.typeText("invalidpassword"));
    
        Intents.init();
        Espresso.onView(ViewMatchers.withId(R.id.login_button)).perform(ViewActions.click());
        Intents.release();
    }
    

    java.lang.NullPointerException is thrown if Intents.init() is not called.

提交回复
热议问题