单击带有Espresso的不完全可见的imageButton [英] Click on not fully visible imageButton with Espresso

查看:88
本文介绍了单击带有Espresso的不完全可见的imageButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义的ImageButton,它在设计上并不完全可见,因此当我执行单击操作时,会出现此错误:

I have a custom ImageButton that is not fully visible, by design, so when I perform a click action I get this error:

android.support.test.espresso.PerformException: Error performing 'single click' on view 'with id: test.com.myproject.app:id/navigationButtonProfile'.
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.
at android.support.test.espresso.ViewInteraction$1.run(ViewInteraction.java:138)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)

按钮的一小部分位于屏幕外部(即裁剪在顶部),也许有12%的按钮位于屏幕外部.这是设计使然,无法滚动或执行任何查看操作以使其可见. 任何人都知道如何克服这一90%的约束吗?

A small part of the button is outside of the screen (i.e. it is cropped on the top), maybe 12% of the button is outside the screen. This is by design, and there is not possible to scroll or perform any view action to make it visible. Any one know how to get past this 90%-constraint?

解决方案: 我按照建议创建了自己的点击动作,并且效果很好. 我从

Solution: I created my own click action as suggested, and it worked perfectly. I copied the class from Google Espresso and changed from 90 to 75 in this method:

    @Override
    @SuppressWarnings("unchecked")
    public Matcher<View> getConstraints() {
        Matcher<View> standardConstraint = isDisplayingAtLeast(75);
        if (rollbackAction.isPresent()) {
            return allOf(standardConstraint, rollbackAction.get().getConstraints());
        } else {
            return standardConstraint;
        }
    }

推荐答案

我认为没有任何简单,优雅的解决方案. 90%约束是硬编码在GeneralClickAction中的,并且该类是最终的,因此我们不能覆盖getConstraints.

I don't think there is any easy, elegant solution to this. The 90% constraint is hardcoded in GeneralClickAction, and the class is final so we can't override getConstraints.

我会基于 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆