2

Я хочу выполнить щелчок по текстовому виду (это текстовое изображение находится под линейным расположением), но оно дает нижеприведенную ошибку. Пробовал Espresso.onData, но он вызывает и другую ошибку. Итак, как использовать Espresso.onData в этом случае?Эспрессо - нажмите на текстовое окно (кнопка)

android.support.test.espresso.NoMatchingViewException: Нет просмотры в иерархии не найдены соответствие: (с идентификатором: выход из системы: ID/Profile_login_logout и имеют родительское соответствие: с идентификатором: выход из системы: идентификатор/main_layout и отображаются на экран для пользователя)

Если цель точка зрения не является частью иерархии представлений, возможно, придется использовать Espresso.onData, чтобы загрузить его из одного из следующих

AdapterViews: android.support.v7.widget .AppCompatSpinner {3ca0fd9d GFED..C. ......Я. 0,0-0,0 # 7f10043a приложение: идентификатор/language_profile_edit}

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

Вот файл XML:

<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

Что значит «под линейной компоновкой»? Является ли «TextView» дочерним элементом «LinearLayout» или «TextView» за «LinearLayout» (используя ту же область на экране)? Отправьте свой макет. – thaussma

+0

TextView является дочерним элементом линейного макета –

+0

Просьба указать свой xml –

ответ

0

Учитывая то, как Humongous макет, я подозреваю, что совпадение allOf() происходит с ошибкой isDisplayed(). Это не удается, когда представление в настоящее время не отображается на экране.

Я действительно не понимаю, почему вам нужны все три устройства для однозначного определения вида. Profile_login_logout представляется уникальным идентификатором, который не требует ничего, кроме withId().

Если вы хотите сделать утверждение, что это представление отображается, вам нужно сначала прокрутить его. Однако scrollTo() проверяет, отображается ли представление после прокрутки как часть вызова perform(). Кроме того, click() имеет isDisplayingAtLeast(90) constrain, запеченный также.

В случае, если вы имеете дело с ViewPager (который я надеюсь, что это не так) или что-то подобное, то вы можете посмотреть на взгляд через его родителей как этот allOf(withId(R.id.Profile_login_logout), hasParent(allOf(withId(R.id.main_layout), isDisplayed()))

onData() не требуется для этого теста, как вы надеваете У меня есть какие-либо виды адаптеров, кроме spinner, которые не являются частью того, что в настоящее время тестируется.

+0

xml-файл был немного длиннее, поэтому я удалил несколько строк. Именно по этой причине макет выглядел хорошо. Итак, как я могу применить это решение к моему коду? , Я вроде как новичок в этом. –

+0

Если мое первоначальное предположение было правильным и причиной отказа является то, что представление отключено от экрана, то ваше ViewInteraction должно выглядеть так: 'withId (R.id.Profile_login_logout)', и это должно работать так, как оно однозначно идентифицирует представление в макет, который вы разместили. –

+0

Я пробовал, но не повезло –

Смежные вопросы