2017-11-02 7 views
1

私は共有環境設定にデータを保存することができます。しかし、私は、ユーザー名とパスワードの両方のフィールドにチェックボックスをオンにしてログインをクリックすると、その部分に突っ込んでしまいました。ログインが成功しました。 testCase userNameは前の提供されたデータで満たされるべきです。私は次のtestCaseのedittextのuserNameフィールドに名前を設定していませんか?エスプレッソを使用して、保存されたデータを次のテストでどのようにチェックできますか?

成功は、この問題をすることができ、私は第二1 testCase.Howでstuckedだ

ユーザ名がNextCase

@Test 
    public void ifCheckBoxisChecked() throws Exception { 
     btnLoginClickWithUserNameAndPasswordProvidedWithCheckedCheckBox(); 

     preferencesEditor.putString("username", "userName"); // Storing string 
     preferencesEditor.commit(); // commit changes 


     onView(withId(R.id.etUsername)).check(matches(withText(userName))); 
    } 

にEDITTEXTにsettedされてどのように

String userName = "984********"; 
    String passWord = "123456789"; 

    Intent intent; 
    SharedPreferences.Editor preferencesEditor; 

    @Test 
    public void btnLoginClickWithUserNameAndPasswordProvidedWithCheckedCheckBox() throws Exception { 

     onView(withId(R.id.etUsername)).perform(typeText(userName)); 
     onView(withId(R.id.etPassword)).perform(typeText(passWord)); 
     onView(withText(R.string.remember_username)).check(matches(isNotChecked())).perform(scrollTo(), setChecked(true)); 
     onView(withId(R.id.btnLogin)).perform(click()); 
//  preferencesEditor.putString("username", "userName"); // Storing string 
//  preferencesEditor.commit(); // commit changes 
    } 

をテストケース解決された??

答えて

1

同じtestCaseのSharedPreferenceのデータをチェックするだけで簡単にアクティビティとStartAgainを終了し、UserNameフィールドがSharedPreference Dataで設定されているかどうかを確認できますか?あなたは参考になりましmightbe testCode

@Test 
    public void btnLoginClickWithUserNameAndPasswordProvidedWithCheckedCheckBox() throws Exception { 
     onView(withId(R.id.etUsername)).perform(clearText()); 
     onView(withId(R.id.etUsername)).perform(typeText(userName)); 
     onView(withId(R.id.etPassword)).perform(typeText(passWord)); 
     onView(withText(R.string.remember_username)).check(matches(isNotChecked())).perform(scrollTo(), setChecked(true)); 
     onView(withId(R.id.btnLogin)).perform(click()); 
     preferencesEditor.putString("username", "userName"); // Storing string 
     preferencesEditor.commit(); // commit changes 
     mActivityRule.getActivity().finish(); 
     mActivityRule.getActivity().startActivity(new Intent(
       mActivityRule.getActivity().getApplicationContext(), mActivityRule.getActivity().getClass())); 
    } 

の下に使用することができます

+0

私は1分であなたをアップするでしょう – Ghimire

+0

あなたは – seon

+0

を更新することができます私は活動が終了し、再オープンする必要がある単純なロジックを欠場しています。あなたの仲間はありがとうございました。 – Ghimire

関連する問題