当我运行android espresso测试时,我得到一个错误:
在id为: is <2131034173>的视图‘com.google.android.apps.common.testing.ui.espresso.PerformException:’上执行‘单击’时,
视图出错。
我的代码很简单:
onView(withId(R.id.btn)).perform(click());
但是下面的代码没有错误:
onView(withId(R.id.btn)).check(matches(isDisplayed()));
我找不到它发生的原因。
发布于 2015-10-02 04:43:25
诀窍是读取错误的完整堆栈跟踪。在中间,有一些关键的信息,比如:
Caused by: 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.
Target view: "ImageView{id=2131492903, res-name=button_hamburger, desc=opens the side drawer, visibility=VISIBLE, width=64, height=64, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=6.0, y=6.0}"
这详细解释了错误。
发布于 2015-04-22 17:07:39
尝试确保软键盘未显示。它可以很容易地用closeSoftKeyboard ViewAction关闭。
此外,请确保禁用了系统动画。在“设置”“->开发选项”下,关闭以下选项:
动画窗口动画scale
此外,这可能是由来自其他应用程序的ANR对话框引起的。
据报道,here也有一个问题。
发布于 2016-04-20 05:59:07
我也有同样的问题,因为软键盘与元素重叠。我使用scrollTo(),然后单击()来解决这个问题。
onView(withId(R.id.btn))
.perform(scrollTo())
.perform(click());
如果以上内容不起作用,请先尝试添加以下内容:
onView(withId(R.id.myEditText)).perform(closeSoftKeyboard());
https://stackoverflow.com/questions/29786413
复制相似问题