2017-02-21 5 views
0

Je commence à écrire des tests d'instrumentation pour mon application avec Espresso, mais j'ai rencontré un problème.Le studio Android ne fonctionne pas

sur mon test lorsque je tente de cliquer sur mon inscription bouton

onData(withId(R.id.signUpButton)).perform(click()); 

Je reçois l'erreur

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

J'ai changé de onView à onData que lors de l'utilisation onView je RECEVOIR l'erreur message

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}

Est-ce que quelqu'un a rencontré des problèmes similaires? Quelle est la meilleure façon de contourner ce problème?

Merci 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> 

+0

Vous devez utiliser 'onView' et comprendre pourquoi exactement aucun bouton n'est présent lorsque vous exécutez votre test –

+0

@bartekLipinski J'ai fait et j'ai reçu cette erreur' Action ne sera pas effectuée car la vue cible ne correspond pas à un ou plusieurs des contraintes suivantes: au moins 90% de la surface de la vue est affichée à l'utilisateur. » –

+0

Oui, vous devez comprendre exactement cela. Lorsque vous commencez votre test d'expresso, ce bouton est-il visible pour vous? –

Répondre

0

Vous devez utiliser la méthode OnView. Votre problème est que l'utilisation d'ID incorrect. Vous avez défini le bouton nommé signButton mais vous utilisez le bouton nommé signUpButton. Vous obtenez donc une erreur.