我不相信这是个愚蠢的问题。我正在编写一个简单的Espresso测试,其中的一部分涉及到点击一个小吃栏中的"Ok“按钮。
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());
这个扔了
使用文本: is“Ok”执行“单次单击”视图的android.support.test.espresso.PerformException:错误。由: java.lang.RuntimeException: Action引起,因为目标视图不匹配以下一个或多个约束:至少90 %的视图区域显示给用户。目标视图:"AppCompatButton{id=2131558552,res-name=snackbar_action,visibility=VISIBLE,width=264,height=144,has focus=false,has focusable=true,has focus=true,is-id=2131558552=true,is-id=2131558552=false,is-调焦=true,is-layout=false,selected=false,is-input-connection=false,x=684.0,y=53.0,text=Ok,输入-type=0,ime- Target =false,has=false}“
有什么想法吗?
发布于 2016-02-24 09:00:33
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
未能被充分显示。
这个问题是由种族状况引起的。您正在尝试打开视图,在视图打开期间,您将尝试单击该视图。如果时机不对,那么只有不到90%的View
可用于click()
的Espresso框架。您可以按照Espresso设置说明中的建议,通过禁用动画来解决这个问题。
Developer Options
我自己的测试表明,您只需将Transition Animation Scale
设置为0.0x
即可。正如您可以想象的,这是一个完全一致的解决方案,您正在经历的种族条件。
发布于 2015-11-01 14:10:53
可以使用id snackbar_action
简单地找到它。
onView(allOf(withId(android.support.design.R.id.snackbar_action)))
.perform(click());
https://stackoverflow.com/questions/33381366
复制相似问题