android - 在 Android 中测试验证
问题描述
嗨,让这个工作有问题,想点击登录按钮并测试验证错误是否出现。我正在使用材料设计验证,这就是我写的
@Test
public void click_login_with_empty_fields_gives_errors() {
onView(withId(R.id.login)).perform(click());
onView(withId(R.id.login_email2)).check(matches(hasErrorText("Email Field cannot be empty")));
onView(withId(R.id.login_password2)).check(matches(hasErrorText("Password field cannot be empty")));
}
我得到的错误是
androidx.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'with error: is "Password field cannot be empty"' doesn't match the selected view.
Expected: with error: is "Password field cannot be empty"
Got: "TextInputEditText{id=2131362003, res-name=login_password2, visibility=VISIBLE, width=996, height=141, has-focus=false, has-focusable=true, has-window-focus=true
解决方案
推荐阅读
- java - 我的方法安全吗?
- html - 如何使用 FlexBox 制作粘性页脚并做出反应
- ios - 添加 HereMaps 后 ipa 文件大小从 10 MB 增加到 300 MB
- php - DataTables 警告:表 id=DataTables_Table_0 - 请求行 0 的未知参数“1”
- indexing - RavenDB 索引中的重音或特殊字符
- android - 没有使用 GSM 下载 Volley 文件
- python - Python:在矩阵中的两个坐标之间画线
- python - 创建一个 new_function,它有一个输入 n 和一个 input_function,它返回一个 output_function,它执行 input_function 的 n 次
- git - 从远程存储库中提取特定标签。
- javascript - 反应 dropzone 不能用 axios 发布