2

Ich möchte klicken Sie auf Textansicht (diese Textansicht ist unter einem linearen Layout), aber es gibt unten genannten Fehler. Versucht Espresso.onData auch aber es wirft einen anderen Fehler auf. So, wie man Espresso.onData in diesem Fall benutzt?Espresso - klicken Sie auf Textansicht (Schaltfläche)

android.support.test.espresso.NoMatchingViewException: Keine Aufrufe in Hierarchie gefunden Matching: (id mit: Abmelden: id/Profile_login_logout und hat zusammenpassende parent: mit id: Abmelden: id/main_layout und wird auf dem angezeigten Bildschirm dem Benutzer)

Wenn die Zielansicht nicht Teil der Ansichtshierarchie ist, müssen Sie Espresso.onData verwenden, um es der folgenden

AdapterViews von einem zu laden: android.support.v7.widget .AppCompatSpinner {3ca0fd9d GFED..C. ......ICH. 0,0-0,0 # 7f10043a App: id/language_profile_edit}

ViewInteraction appCompatTextView5 = onView(
allOf(withId(R.id.Profile_login_logout), 
withParent(withId(R.id.main_layout)), 
isDisplayed())); 
appCompatTextView5.perform(scrollTo(), click()); 

ist die XML-Datei:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@color/dull_gray"> 

<ProgressBar 
    android:id="@+id/progress_profile" 
    style="?android:progressDrawable" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" 
    android:visibility="gone" /> 

<TextView 
    android:id="@+id/text_loading_profile" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/progress_profile" 
    android:layout_centerHorizontal="true" 
    android:text="@string/loading" 
    android:visibility="gone" /> 

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <LinearLayout 
     android:id="@+id/main_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/profile_bg"> 

      <RelativeLayout 
       android:id="@+id/person_image_profile_containner" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"> 

       <ImageView 
        android:id="@+id/person_image_profile" 
        android:layout_alignParentLeft="true" 
        android:layout_centerVertical="true" 
        android:padding="@dimen/margin20" /> 
      </RelativeLayout> 

      <ProgressBar 
       android:id="@+id/progress_image_profile" 
       style="?android:progressDrawable" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:layout_centerVertical="true" 
       android:visibility="gone" /> 

      <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerVertical="true" 
       android:layout_margin="@dimen/topMarginU2" 
       android:layout_toRightOf="@+id/person_image_profile_containner"> 

       <TextView 
        android:id="@+id/person_name_profile" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentTop="true"/> 

       <EditText 
        android:id="@+id/person_name_profile_edit" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentTop="true" 
        android:hint="@string/enter_name" 
        android:visibility="gone" /> 

       <RelativeLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"> 

        <TextView 
         android:id="@+id/mobile_profile_initial" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_marginTop="@dimen/topMargin" 
         android:textSize="@dimen/txtSizeS" 
         tools:ignore="HardcodedText" /> 

        <EditText 
         android:id="@+id/mobile_profile_edit_initial" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:editable="false" 
         android:layout_alignParentBottom="true" 
         android:visibility="gone" 
         tools:ignore="HardcodedText" /> 

       </RelativeLayout> 


       <EditText 
        android:id="@+id/email_profile_edit" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:visibility="gone" /> 
      </LinearLayout> 
     </RelativeLayout> 

     <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:card_view="http://schemas.android.com/apk/res-auto" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:focusable="true"> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 

     <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="horizontal"> 

        <TextView 
         android:layout_height="wrap_content" 
         android:paddingLeft="@dimen/topMarginU2" 
         android:text="@string/language"/> 

        <Spinner 
         android:id="@+id/language_profile_edit" 
         android:layout_height="wrap_content"/> 
       </LinearLayout> 

       <LinearLayout 
        android:id="@+id/selected_exams" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="horizontal"> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="@string/selected_exams"/> 
       </LinearLayout> 

       <RelativeLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content"> 

        <android.support.v7.widget.RecyclerView 
         android:id="@+id/horiz_scroll_exams" 
         android:layout_width="wrap_content" 
         android:layout_centerVertical="true" 
         android:scrollbars="horizontal" /> 
       </RelativeLayout> 

       <LinearLayout 
        android:id="@+id/personal_information" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content"> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_alignParentLeft="true" 
         android:padding="@dimen/topMarginU2" 
         android:text="@string/personal_information"/> 
       </LinearLayout> 

       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="horizontal"> 

        <TextView 
         android:layout_height="wrap_content" 
         android:layout_alignParentLeft="true" 
         android:text="@string/date_of_birth" 
         android:textSize="@dimen/textSize16" /> 

       </LinearLayout> 

       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="horizontal"> 

        <TextView 
         android:layout_width="0dp" 
         android:layout_height="wrap_content" 
         android:text="@string/qualification" 
         android:textSize="@dimen/textSize16" /> 

        <Spinner 
         android:id="@+id/qualification_profile_edit" 
         android:layout_height="wrap_content" 
         android:layout_marginLeft="@dimen/topMargin" 
         android:padding="@dimen/topMarginU2" 
         android:textSize="@dimen/textSize16" 
         android:visibility="gone" /> 
       </LinearLayout> 

       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="horizontal"> 

        <TextView 
         android:id="@+id/Personal_address" 
         android:layout_height="wrap_content" 
         android:text="@string/address" 
         android:textSize="@dimen/textSize16" /> 

        <LinearLayout 
         android:layout_height="wrap_content" 
         android:orientation="vertical"> 

         <TextView 
          android:id="@+id/address_basic" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:paddingLeft="@dimen/topMarginU2" 
          tools:ignore="HardcodedText" /> 

         <EditText 
          android:id="@+id/edit_address_basic" 
          android:layout_width="match_parent" 
          android:layout_height="wrap_content" 
          android:layout_marginLeft="@dimen/topMarginU2" 
          android:layout_marginTop="@dimen/topMarginU1" 
          android:hint="@string/enter_address" 
          android:visibility="gone" /> 


         <Spinner 
          android:id="@+id/edit_address_state" 
          android:layout_width="match_parent" 
          android:layout_height="wrap_content" 
          android:layout_marginLeft="@dimen/topMargin" 
          android:textSize="@dimen/txtSizeS" 
          android:visibility="gone" /> 
        </LinearLayout> 

       </LinearLayout> 


       <View 
        android:layout_width="match_parent" 
        android:background="@color/dull_gray" /> 

       <RelativeLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="horizontal"> 

        <TextView 
         android:id="@+id/title5" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_alignParentLeft="true" 
         android:layout_centerVertical="true" 
         android:textSize="@dimen/txtSize" /> 

        <ImageView 
         android:id="@+id/dot1" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_centerInParent="true" 
         android:src="@drawable/dot" /> 

       </RelativeLayout> 



      </LinearLayout> 
     </android.support.v7.widget.CardView> 


     <TextView 
      android:id="@+id/Profile_login_logout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_above="@+id/signup_splash_tv" 
      android:layout_centerHorizontal="true" /> 
    </LinearLayout> 
</ScrollView> 

+0

Was meinst du mit "unter einem linearen Layout"? Ist 'TextView' ein Kind des' LinearLayout' oder ist 'TextView' hinter dem' LinearLayout' (mit derselben Region auf dem Bildschirm)? Veröffentlichen Sie Ihr Layout. – thaussma

+0

TextView ist Kind des linearen Layouts –

+0

Bitte posten Sie Ihre xml –

Antwort

0

Bedenkt man, wie humongous das Layout ist, vermute ich, dass der allOf() Matcher bei isDisplayed() ausfällt. Was fehlschlägt, wenn die Ansicht nicht auf dem Bildschirm angezeigt wird.

Ich sehe nicht wirklich, warum Sie alle drei Matcher benötigen, um die Ansicht eindeutig zu identifizieren. Profile_login_logout scheint eine eindeutige ID zu sein, die nichts anderes als withId() Matcher erfordert.

Wenn Sie eine Assertion erstellen möchten, dass diese Ansicht angezeigt wird, müssen Sie zuerst zu dieser Ansicht blättern. scrollTo() überprüft jedoch, ob die Ansicht nach dem Bildlauf als Teil des Aufrufs perform() angezeigt wird. Darüber hinaus click() hat isDisplayingAtLeast(90) Constrain auch gebacken.

Falls Sie mit einem ViewPager tun haben (was ich hoffe, ist nicht der Fall ist) oder etwas ähnliches Sie dieses allOf(withId(R.id.Profile_login_logout), hasParent(allOf(withId(R.id.main_layout), isDisplayed()))

onData() ist für diesen Test nicht, wie Sie don erforderlich für die Ansicht durch seine Eltern sehen können Es gibt keine anderen Adapteransichten als spinner, die nicht zu dem gehören, was gerade getestet wird.

+0

XML-Datei war etwas länger, deshalb habe ich einige Zeilen entfernt. Dies ist der Grund, Layout sah gut aus. Wie soll ich diese Lösung auf meinen Code anwenden? Ich bin etwas neu dazu. –

+0

Wenn meine ursprüngliche Annahme korrekt war und der Grund für den Fehler ist, dass die Ansicht nicht auf dem Bildschirm ist, dann sollte Ihre ViewInteraction folgendermaßen aussehen: 'withId (R.id.Profile_login_logout)' und das sollte funktionieren, da es die Ansicht eindeutig identifiziert das Layout, das du gepostet hast. –

+0

Ich hatte es versucht aber kein Glück –

Verwandte Themen