Espresso测试无法在某些设备上单击DialogBu​​tton

时间:2019-02-21 12:25:01

标签: android android-espresso

我有一个Espresso-Test,用于验证显示的对话框。它按下一个按钮来打开对话框,并且应该通过单击对话框的肯定按钮将其关闭。该对话框可以很好地打开,但是在两个三星设备(Samsung S6 Edge和Samsung S7)上单击对话框的肯定按钮均会失败,但在所有其他设备上都可以使用。我尝试了以下解决方案:

通过按钮上的文字匹配按钮 onView(withText(R.string.changelog_ok_button)).perform(click())

通过由Android OS分配给肯定的对话框按钮的ID来匹配按钮: onView(withId(android.R.id.button1)).perform(click())

这两种解决方案均可在大多数设备上使用,但表示三星拒绝执行点击操作,并出现以下错误:

android.support.test.espresso.PerformException: Error performing 'single click' on view 'with string from resource id: <2131755113>[changelog_ok_button] value: OK'.
[...]
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: "AppCompatButton{id=16908313, res-name=button1, visibility=VISIBLE, width=192, 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, layout-params=android.widget.LinearLayout$LayoutParams@ab3a33, tag=null, root-is-layout-requested=false, has-input-connection=false, x=666.0, y=12.0, text=OK, input-type=0, ime-target=false, has-links=false}"

最令人困惑的是,当我使用布局检查器时,按钮的ID为R.id.button1,并且其文本也与R.string.changelog_ok_button匹配。

三星对于可能导致此问题的对话框有何不同之处?有人遇到了同样的问题并找到了解决方案,或者对我如何使它起作用有想法?

1 个答案:

答案 0 :(得分:0)

根据错误描述很明显:

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.

因此,我想有问题的设备在屏幕显示分辨率较小的情况下会稍微切掉或隐藏按钮视图,因此向用户显示的视图区域低于90%。