我正在使用Espresso创建测试。用户进入注册屏幕,输入详细信息,成功注册用户。然后,用户进入登录屏幕,输入用户名并进入仪表板。仪表板上有一条消息向用户打招呼。
该测试运行正常,但在检查仪表板消息时失败。它应该说“ Welcome {用户的全名}”。但是错误日志指出它失败了:
android.support.test.espresso.base.DefaultFailureHandler $ AssertionFailedWithCauseError: 'with text:is“ Welcome Jane Doe”'与所选视图不匹配。 预期:带有文字:是“ Welcome Jane Doe”
这是我的考试:
// Test when user tries to register with alpha numeric character and correct email format, register user. Go to login screen and
// login to the dashboard. Should only display full name
@Test
public void testRegisterWithValidUsernameEmailThenLogin(){
// register user
onView(ViewMatchers.withId(R.id.usernameEditText)).perform(clearText(), typeText(studentFullNameTwo.getUsername()), closeSoftKeyboard());
onView(ViewMatchers.withId(R.id.emailEditText)).perform(clearText(), typeText(studentFullNameTwo.getEmail()), closeSoftKeyboard());
onView(ViewMatchers.withId(R.id.registerButton)).perform(click());
// login with new user
onView(ViewMatchers.withId(R.id.editTextUsername)).perform(clearText(), typeText(studentFullNameTwo.getUsername()), closeSoftKeyboard());
onView(ViewMatchers.withId(R.id.buttonLogin)).perform(click());
// check welcome header
String fullName = studentFullNameTwo.getFirstName() + " " + studentFullNameTwo.getLastName();
// Change view to dashboard screen
onView(withId(R.id.loggedUserDashHeader)).check(matches(withText("Welcome " + fullName)));
}