Android Studio点击不执行



我开始使用浓缩咖啡为我的应用程序编写仪器测试,但是我遇到了问题。

尝试单击我的注册按钮

时在测试中
onData(withId(R.id.signUpButton)).perform(click());

我得到错误

android.support.test.espresso.PerformException: Error performing 'load adapter data' on view 'is assignable from class: class android.widget.AdapterView'.

我从onView更改为onData,就像使用onView时,我正在接收错误消息

android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id: uk.co.vouchercodes.android.beta:id/signUpButton If the target view is not part of the view hierarchy, you may need to use Espresso.onData to load it from one of the following AdapterViews:android.widget.GridView{5c810ee VFED..C.. ........ 0,0-1080,1376 #7f1001f0 app:id/onboardingMerchantGridView}

有人遇到类似问题吗?关于这个问题的最好方法是什么?

谢谢 xml

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:clickable="true"
    android:background="@color/vc_green_5_onboarding"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<ProgressBar
        android:id="@+id/progressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:visibility="invisible"/>
<ScrollView
        android:id="@+id/authScrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    <LinearLayout
            style="@style/PaddedLayout"
            android:orientation="vertical">
        <TextView
                android:id="@+id/authTitleTextView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                tools:text="AUTH TITLE"
                android:layout_marginTop="@dimen/margin_top"
                android:textStyle="bold"
                android:gravity="center"
                android:layout_marginBottom="@dimen/spacing_standard"/>
        <LinearLayout
                android:id="@+id/signupContentLayout1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
            <ImageView
                    android:layout_width="@dimen/spacing_double"
                    android:layout_height="match_parent"
                    android:layout_marginRight="@dimen/spacing_standard"
                    android:src="@drawable/name_icon"
                    android:scaleType="fitStart"
                    android:tint="@color/white"/>
            <EditText
                    android:id="@+id/nameField"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:hint="@string/name"
                    android:textColorHint="@color/white"
                    android:paddingBottom="@dimen/spacing_half"
                    android:layout_marginBottom="@dimen/spacing_standard"
                    android:background="@drawable/authorization_edittext"
                    android:inputType="textCapWords|textPersonName"
                    android:singleLine="true"/>
        </LinearLayout>
        <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
            <ImageView
                    android:layout_width="@dimen/spacing_double"
                    android:layout_height="match_parent"
                    android:layout_marginRight="@dimen/spacing_standard"
                    android:src="@drawable/email_icon"
                    android:scaleType="fitStart"
                    android:tint="@color/white"/>
            <AutoCompleteTextView
                    android:id="@+id/emailField"
                    android:layout_width="0px"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:hint="@string/email"
                    android:textColorHint="@color/white"
                    android:paddingBottom="@dimen/spacing_half"
                    android:layout_marginBottom="@dimen/spacing_standard"
                    android:background="@drawable/authorization_edittext"
                    android:imeOptions="actionNext"
                    android:inputType="textEmailAddress"
                    android:singleLine="true"/>
        </LinearLayout>
        <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
            <ImageView
                    android:id="@+id/passwordLabel"
                    android:layout_width="@dimen/spacing_double"
                    android:layout_height="match_parent"
                    android:layout_marginRight="@dimen/spacing_standard"
                    android:src="@drawable/password_icon"
                    android:scaleType="fitStart"
                    android:tint="@color/white"/>
            <EditText
                    android:id="@+id/passwordField"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:hint="@string/password"
                    android:textColorHint="@color/white"
                    android:paddingBottom="@dimen/spacing_half"
                    android:layout_marginBottom="@dimen/spacing_standard"
                    android:background="@drawable/authorization_edittext"
                    android:inputType="textPassword"
                    android:singleLine="true"/>
        </LinearLayout>
        <TextView
                android:id="@+id/forgotPasswordText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/forgot_password"
                android:background="@android:color/transparent"
                android:gravity="center"
                android:paddingBottom="10dp"/>
        <Button
                android:id="@+id/signButton"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="@string/sign_up"
                android:layout_marginTop="@dimen/spacing_standard"
                android:background="@drawable/btn_auth_white_stroke"/>
        <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="@string/onboarding_or"
                android:textStyle="bold"
                android:layout_margin="@dimen/margin_top"/>
        <Button
                android:id="@+id/facebookButton"
                android:layout_width="wrap_content"
                android:layout_height="@dimen/onboarding_button_height"
                android:text="@string/facebook_connect"
                android:layout_gravity="center"
                android:background="@drawable/btn_facebook_background"
                android:paddingLeft="40dp"/>
        <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center">
            <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/icon_padlock"
                    android:padding="4dp"/>
            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/facebook_no_post"
                    android:textSize="@dimen/text_size_small"
                    android:textStyle="bold"
                    android:padding="4dp"/>
        </LinearLayout>
        <TextView
                android:id="@+id/switchTextView"
                android:layout_width="@dimen/onboarding_privacy_and_terms_width"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/margin_top"
                android:text="@string/auth_switch_to_signin"
                android:layout_gravity="center"
                android:textSize="@dimen/onboarding_text_size_pin"
                android:textStyle="bold"
                android:gravity="center"/>
        <TextView
                android:id="@+id/privacyTermsText"
                android:layout_width="@dimen/onboarding_privacy_and_terms_width"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/margin_top"
                android:layout_gravity="center"
                android:textSize="@dimen/text_size_small"
                android:textStyle="bold"
                android:gravity="center"
                tools:text="@string/auth_privacy_terms"
                android:layout_marginBottom="@dimen/spacing_standard"/>
    </LinearLayout>
</ScrollView>

您应该使用onview方法。您的问题是使用错误的ID。您定义了名为Signbutton的按钮,但是您使用的按钮称为IngiupButton,因此您会遇到错误。

最新更新