gpt4 book ai didi

android - Espresso 断言文本匹配但仍然失败

转载 作者:行者123 更新时间:2023-12-05 00:06:25 28 4
gpt4 key购买 nike

我正在使用 Espresso 来创建测试。用户进入注册界面,输入详细信息,成功注册用户。用户然后进入登录屏幕,输入用户名并进入仪表板。仪表板有一条向用户打招呼的消息。

测试运行良好,但在检查仪表板消息时失败。它应该说“欢迎{用户的全名}”。但是错误日志表明它失败了:

android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'with text: is "Welcome Jane Doe"' doesn't match the selected view. Expected: with text: is "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)));
}

最佳答案

我上周进入了这个问题。它可能会迟到,但它可能会在 future 帮助一些人。
我创建了一个代表编码空间的变量。

private const val ENCODE_SPACE = '\u00A0'
然后,使用编码空间而不是空字符串。
 "Welcome${ENCODE_SPACE}"
就我而言,问题来自项目其他部分的字符串连接。这是项目中可重用的代码。

关于android - Espresso 断言文本匹配但仍然失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52895601/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com