use*_*ser 9 java android android-espresso android-snackbar
我不相信这是一个愚蠢的问题.我正在写一个简单的Espresso测试,其中一部分涉及点击快餐栏中的"确定"按钮.
Espresso.onView(allOf(withId(android.support.design.R.id.snackbar_text), withText(R.string.permission_snackbar)))
.check(matches(isDisplayed()));
Espresso.onView(withText("Ok")).perform(click());
Run Code Online (Sandbox Code Playgroud)
这引发了
android.support.test.espresso.PerformException:在带有text的视图'上执行'单击'时出错:是"Ok"'.引发者:java.lang.RuntimeException:将不执行操作,因为目标视图与以下一个或多个约束不匹配:至少90%的视图区域显示给用户.目标视图:"AppCompatButton {id = 2131558552,res-name = snackbar_action,visibility = VISIBLE,width = 264,height = 144,has-focus = false,has-focusable = true,has-window-focus = true,is- clickable = true,is-enabled = true,is-focused = false,is-focusable = true,is-layout-requested = false,is-selected = false,root-is-layout-requested = false,has-input- connection = false,x = 684.0,y = 53.0,text = Ok,input-type = 0,ime-target = false,has-links = false}"
有任何想法吗?
在这RuntimeException看到java.lang.RuntimeException: Action will not be performed because the target view does not match one or more of the following constraints: at least 90 percent of the view's area is displayed to the user..事实上,问题确实来自于View完全显示的失败.
问题是由竞争条件引起的.您正在尝试打开视图,并在打开视图时尝试单击它.如果时机不对,那么ViewEspresso框架可用的比例不到90%click().您可以按照"浓咖啡设置说明"中的建议,通过禁用动画来解决问题
Developer Options我自己的测试表明您可以只设置脱身Transition Animation Scale来0.0x.您可以想象,这是您遇到的竞争条件的完美一致的解决方案.
可以简单地使用 id 找到它snackbar_action:
onView(allOf(withId(android.support.design.R.id.snackbar_action)))
.perform(click());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1701 次 |
| 最近记录: |