层次结构中的任何视图都未找到匹配的Android Espresso

时间:2017-10-01 06:22:08

标签: android unit-testing android-espresso

>     >     android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id:
> com.allion.medimap:id/loginbutton
>     >     
>     >     View Hierarchy:
>     >     +>DecorView{id=-1, visibility=VISIBLE, width=60, height=60, has-focus=false, has-focusable=false, 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=false, x=0.0,
>     > y=0.0, child-count=1}
>     >     |
>     >     +->FrameLayout{id=-1, visibility=VISIBLE, width=60, height=60, has-focus=false, has-focusable=false,
> 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=false, x=0.0,
>     > y=0.0, child-count=2}
>     >     |
>     >     +-->FrameLayout{id=16908290, res-name=content, visibility=VISIBLE, width=60, height=60, has-focus=false,
> has-focusable=false,
>     > 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=false, x=0.0, y=0.0, child-count=1}
>     >     |
>     >     +--->LinearLayout{id=-1, visibility=VISIBLE, width=60, height=60, has-focus=false, has-focusable=false,
> 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=false, x=0.0,
>     > y=0.0, child-count=1}
>     >     |
>     >     +---->AVLoadingIndicatorView{id=-1, visibility=VISIBLE, width=60, height=60, has-focus=false, has-focusable=false,
>     > 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=false, x=0.0, y=0.0}
>     >     |
>     >     +-->ViewStub{id=16909337, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true,
>     > is-clickable=false, is-enabled=true, is-focused=false,
>     > is-focusable=false, is-layout-requested=true, is-selected=false,
>     > root-is-layout-requested=false, has-input-connection=false, x=0.0,
>     > y=0.0}

|

我尝试检查我的LoginActivity类中的登录按钮。我为这两个类使用了相同的资源ID。在下面我附上了我的LoginActivity类登录按钮功能

login = (Button) findViewById(R.id.loginbutton);
        login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (Validator.isEmpty(LoginActivity.this, patientaddresstext) && Validator.isEmpty(LoginActivity.this, patientemegencynametext) && Validator.validateMobileNumber(LoginActivity.this, patientemegencynumbertext)) {
                    startSendPatientInfoRequestEvent();
                }

            }
        });
  

login_activity.xml

 <?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rel"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/linearLayout"
        android:scrollbars="vertical"

        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:gravity="center_horizontal"
        android:orientation="vertical"
    >
        <Button
            android:id="@+id/loginbutton"
            android:layout_width="match_parent"
            android:layout_height="35dp"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="30dp"
            android:layout_marginTop="30dp"
            android:background="@drawable/whitebuttonshape"
            android:textAllCaps="false"
            android:textStyle="bold"
            android:text="@string/next"
            android:textColor="@color/blue_text"
            tools:textAllCaps="false" />

        <!--Back-->
        <Button
            android:id="@+id/backbutton"
            android:layout_width="match_parent"
            android:layout_height="35dp"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="30dp"
            android:textStyle="bold"
            android:layout_marginTop="15dp"
            android:background="@drawable/buttonshape"
            android:textAllCaps="false"
            android:text="@string/back"
            android:textColor="@color/white_text"
            tools:textAllCaps="false" />
        <android.support.v4.widget.Space
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.4"/>
    </LinearLayout>

</RelativeLayout>
  

但是当我通过手机测试时我得到了一个例外。我将activity_login.xml添加到这里。我也使用了相同的id名称。我是使用Esspresso进行android测试的新手。如果有人可以帮助解决这个问题它会让我感激不尽。

0 个答案:

没有答案
相关问题