Espresso:匹配层次结构中的多个视图

Espresso: matches multiple views in the hierarchy

我有注册对话框,我需要测试使用 Espresso,但我总是收到错误 "matches multiple views in the hierarchy"。

部分注册对话框:

<com.rey.material.widget.EditText
            android:id="@+id/input_name"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:layout_gravity="center"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginTop="8dp"
            android:hint="@string/name_hint_registration_dialog"
            android:inputType="text"
            android:textSize="18sp"
            app:et_dividerColor="@color/my_primary"
            app:et_dividerHeight="1dp"
            app:et_labelEnable="true"
            app:et_labelTextColor="@color/my_primary"
            app:et_labelTextSize="14sp"
            app:et_supportLines="1"/>

我的简单代码:

onView(withId(R.id.input_name))
                .perform(typeText(numberEnter));

错误:

android.support.test.espresso.AmbiguousViewMatcherException: '(with id: com.zf.openmaticsdetagtive:id/input_name and has content description)' 匹配层次结构中的多个视图。 问题视图在下方标有“****匹配****”。

+----->EditText{id=2131689737, res-name=input_name, desc=Name, visibility=VISIBLE, width=730, height=64, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=true, editor-info=[inputType=0x1 imeOptions=0x8000005 privateImeOptions=null actionLabel=null actionId=0 initialSelStart=0 initialSelEnd=0 initialCapsMode=0x0 hintText=Name label=null packageName=null fieldId=0 fieldName=null extras=null ], x=21.0, y=96.0, child-count=2} ****MATCHES****

+------>InternalEditText{id=2131689737, res-name=input_name, desc=Name, visibility=VISIBLE, width=730, height=38, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=true, is-focusable=true, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=true, editor-info=[inputType=0x1 imeOptions=0x8000005 privateImeOptions=null actionLabel=null actionId=0 initialSelStart=0 initialSelEnd=0 initialCapsMode=0x0 hintText=Name label=null packageName=null fieldId=0 fieldName=null extras=null ], x=0.0, y=26.0, text=, hint=Name, input-type=1, ime-target=true, has-links=false} ****MATCHES****

我确定我没有任何其他元素具有此 ID,但什么会导致此问题? InternalEditText 和 EditText 有什么区别?可能是我正在使用 com.rey.material.widget.EditText? 在此先感谢您的帮助或提示

是的。
看来你的假设是正确的。
Material Lib 使用名为 InternalEditText 的内部视图。

您将需要指定一个额外的匹配器来匹配正确的视图。