Android 如何使用浓缩咖啡检查保存的数据以备下次测试?
我可以将数据保存到共享的首选项中。但有一部分我被绊倒了,当用户名和密码字段都带有复选框时,单击登录。然后登录成功。在另一个测试用例中,用户名应该用之前提供的数据填充。在下一个测试用例中,我没有在edittext中的用户名字段中设置名称 成功测试案例Android 如何使用浓缩咖啡检查保存的数据以备下次测试?,android,sharedpreferences,android-espresso,Android,Sharedpreferences,Android Espresso,我可以将数据保存到共享的首选项中。但有一部分我被绊倒了,当用户名和密码字段都带有复选框时,单击登录。然后登录成功。在另一个测试用例中,用户名应该用之前提供的数据填充。在下一个测试用例中,我没有在edittext中的用户名字段中设置名称 成功测试案例 String userName = "984********"; String passWord = "123456789"; Intent intent; SharedPreferences.Editor prefere
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
}
如何在NextCase的editText中设置用户名
我在第二个一级测试用例中被绊倒了。如何解决这个问题???您只需检查同一测试用例上的SharedReference数据。您只需完成活动并开始检查用户名字段是否设置了SharedReference数据 您可以使用下面的测试代码 那可能对你有帮助
我会在一分钟内告诉你我错过了一个简单的逻辑,那就是活动应该结束并重新开始。你的同事谢谢你。
@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)));
}
@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()));
}