2

我想执行点击TextView的(这TextView的是一种线性布局下),但它提供了以下提到的错误。尝试了Espresso.onData,但它引发了一些其他错误。那么如何在这种情况下使用Espresso.onData?咖啡 - 点击的TextView(按钮)

android.support.test.espresso.NoMatchingViewException:在体系中没有的观点找到匹配:(id为:注销:ID/Profile_login_logout并具有父匹配:id为:注销:ID/main_layout并显示在屏幕给用户)

如果目标视图不是视图层次的一部分,您可能需要使用Espresso.onData加载它从以下

AdapterViews之一:android.support.v7.widget .AppCompatSpinner {3ca0fd9d GFED..C。 ......一世。 0,0-0,0#7f10043a应用: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()); 

下面是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”的子项还是“LinearLayout”后面的“TextView”(使用屏幕上的相同区域)?发布您的布局。 – thaussma

+0

TextView是Linear layout的子版本 –

+0

请发布您的xml –

回答

0

鉴于布局如何堆积如山的是,我怀疑allOf()匹配器在isDisplayed()失败。当视图当前没有显示在屏幕上时失败。

我真的不明白为什么你需要的所有三个匹配器唯一标识视图。 Profile_login_logout似乎是一个唯一的ID,它不需要除了匹配器之外的其他东西。

如果你想,这个观点显示你需要先滚动到它的断言。但scrollTo()将检查作为perform()呼叫的一部分滚动后是否显示视图。此外click()也有isDisplayingAtLeast(90)限制烘烤。

在你正在处理一个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

我曾试过但没有运气 –