web-dev-qa-db-ja.com

ナビゲーションボタンをクリックしようとしたときのEspressoAmbiguousViewMatcherException

私がやろうとしているテスト:購入し、タイトルをメモしてから、ホームアクティビティに戻り、画像ボタンである「home_image」を押します。

私の問題は、home_imageをナビゲートできないことです。それを押すと、偽の重複IDを取得します。重複したIDは、同じIDを持つ非表示のフラグメントを参照していると思います。テストの開始時にそれが問題にならない理由は奇妙です。テキストの制限により、申し訳ありませんがログを切り捨てる必要がありました。私がやりたいのは、ホームアクティビティを直接開始することですが、このスイートは、単純なことを行うのに半分の苦痛です。スワイプコマンドでもこのエラーが発生します!これらすべてのボタンが初めて機能するときは、エスプレッソのエラーだと思います。回避策が必要です。

あなたのアイデアをありがとう!

    mSectionsPagerAdapter = new SectionsPagerAdapter( getFragmentManager() );

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPagerExtended) findViewById( R.id.pager );
    mViewPager.setAdapter( mSectionsPagerAdapter );
    mViewPager.setSwipeEnabled( true );

    final ImageButton homeImageButton = (ImageButton) findViewById( R.id.home_image );
    final ImageButton exploreImageButton = (ImageButton) findViewById( R.id.explore_image );
    final ImageButton profileImageButton = (ImageButton) findViewById( R.id.profile_image );

    mViewPager.setOnPageChangeListener( new ViewPager.SimpleOnPageChangeListener()
    {
        @Override
        public void onPageSelected( int position )
        {
            switch ( position )
            {
                case 0:
                    homeImageButton.setImageResource( R.drawable.home_icon );
                    exploreImageButton.setImageResource( R.drawable.explore_icon_inactive );
                    profileImageButton.setImageResource( R.drawable.profile_icon_inactive );
                    break;
                case 1:
                    homeImageButton.setImageResource( R.drawable.home_icon_inactive );
                    exploreImageButton.setImageResource( R.drawable.explore_icon );
                    profileImageButton.setImageResource( R.drawable.profile_icon_inactive );
                    break;
                case 2:
                    homeImageButton.setImageResource( R.drawable.home_icon_inactive );
                    exploreImageButton.setImageResource( R.drawable.explore_icon_inactive );
                    profileImageButton.setImageResource( R.drawable.profile_icon );
                    break;
            }
        }
    } );

    homeImageButton.setOnClickListener( new View.OnClickListener()
    {
        @Override
        public void onClick( View v )
        {
            mViewPager.setCurrentItem( 0 );
        }
    } );

    exploreImageButton.setOnClickListener( new View.OnClickListener()
    {
        @Override
        public void onClick( View v )
        {
            mViewPager.setCurrentItem( 1 );
        }
    } );

    profileImageButton.setOnClickListener( new View.OnClickListener()
    {
        @Override
        public void onClick( View v )
        {
            mViewPager.setCurrentItem( 2 );
        }
    } );

//ここにレイアウト

<RelativeLayout xmlns:Android="http://schemas.Android.com/apk/res/Android"
            xmlns:app="http://schemas.Android.com/apk/res-auto"
            Android:layout_width="match_parent"
            Android:layout_height="match_parent"
            Android:tag="default"
            Android:id="@+id/home"
    >

<LinearLayout
        Android:id="@+id/tab_bar"
        Android:layout_width="match_parent" Android:layout_height="48dp"
        Android:background="@color/****_orange_light"
        Android:gravity="center"
        >

    <ImageButton
            Android:id="@+id/home_image"
            Android:layout_width="0dp" Android:layout_height="match_parent"
            Android:src="@drawable/home_icon"
            Android:layout_weight="1"
            Android:background="#00000000"
            />
    <ImageButton
            Android:id="@+id/explore_image"
            Android:layout_width="0dp" Android:layout_height="match_parent"
            Android:src="@drawable/explore_icon_inactive"
            Android:layout_weight="1"
            Android:background="#00000000"
            />
    <ImageButton
            Android:id="@+id/profile_image"
            Android:layout_width="0dp" Android:layout_height="match_parent"
            Android:src="@drawable/profile_icon_inactive"
            Android:layout_weight="1"
            Android:background="#00000000"
            />

    <Android.support.v7.app.MediaRouteButton
            Android:id="@+id/media_route_button"
            Android:layout_width="0dp"
            Android:layout_height="wrap_content"
            Android:layout_weight="1"
            Android:mediaRouteTypes="user"
            Android:visibility="gone"

//テスト出力

Running tests
Test running started
Android.support.test.espresso.AmbiguousViewMatcherException: 'with id: com.*******.main:id/home_image' matches multiple views in the hierarchy.
Problem views are marked with '****MATCHES****' below.

View Hierarchy:
+>DecorView{id=-1, visibility=VISIBLE, width=1080, height=1776, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}
|
+->LinearLayout{id=-1, visibility=VISIBLE, width=1080, height=1776, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}
|
+-->ViewStub{id=16909070, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0}
|
+-->FrameLayout{id=-1, visibility=VISIBLE, width=1080, height=1701, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=75.0, child-count=1}
|
+--->FitWindowsLinearLayout{id=2131492941, res-name=action_bar_root, visibility=VISIBLE, width=1080, height=1701, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}
|
+---->ViewStubCompat{id=2131492942, res-name=action_mode_bar_stub, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0}
|
+---->NativeActionModeAwareLayout{id=16908290, res-name=content, visibility=VISIBLE, width=1080, height=1701, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}
|
+----->RelativeLayout{id=2131492921, res-name=home, visibility=VISIBLE, width=1080, height=1701, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}
|
+------>LinearLayout{id=2131493015, res-name=tab_bar, visibility=VISIBLE, width=1080, height=144, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=4}
|
+------->ImageButton{id=2131493016, res-name=home_image, visibility=VISIBLE, width=360, height=144, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0} ****MATCHES****
|
+------->ImageButton{id=2131493017, res-name=explore_image, visibility=VISIBLE, width=360, height=144, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=360.0, y=0.0}
|
+------->ImageButton{id=2131493018, res-name=profile_image, visibility=VISIBLE, width=360, height=144, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=720.0, y=0.0}
|
+------->MediaRouteButton{id=2131493019, res-name=media_route_button, desc=Cast, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=true, is-enabled=false, is-focused=false, is-focusable=true, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0}
|
+------>ViewPagerExtended{id=2131493020, res-name=pager, visibility=VISIBLE, width=1080, height=1557, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=144.0, child-count=3}
|
+------->LinearLayout{id=2131493215, res-name=fragment_member_home, visibility=VISIBLE, width=1080, height=1557, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=-1080.0, y=0.0, child-count=3}
|
+-------->PagerSlidingTabStrip{id=2131493216, res-name=member_home_tabs, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}
|
+--------->LinearLayout{id=-1, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}
|
+---------->TextView{id=-1, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=MY CLASSES, input-type=0, ime-target=false, has-links=false}
|
+---------->TextView{id=-1, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=MY PATTERNS, input-type=0, ime-target=false, has-links=false}
|
+-------->View{id=-1, visibility=VISIBLE, width=1080, height=3, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0}
|
+-------->ViewPagerExtended{id=2131493217, res-name=member_home_view_pager, visibility=VISIBLE, width=1080, height=1554, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=3.0, child-count=2}
|
+--------->RelativeLayout{id=-1, visibility=VISIBLE, width=1080, height=1554, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}
|
+---------->SwipeRefreshLayout{id=2131493222, res-name=swipe_container, visibility=VISIBLE, width=1080, height=1554, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}
|
+----------->CircleImageView{id=-1, visibility=GONE, width=140, height=140, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=470.0, y=-140.0}
|
+----------->ListView{id=2131493178, res-name=courseGridView, visibility=VISIBLE, width=1080, height=1554, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}
|
+------------>LinearLayout{id=-1, visibility=VISIBLE, width=1080, height=905, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}
|
+------------->RelativeLayout{id=2131493121, res-name=courseGridCell, visibility=VISIBLE, width=1080, height=905, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=6}
|
+-------------->FrameLayout{id=2131493122, res-name=courseImageFrame, visibility=VISIBLE, width=1080, height=613, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}
|
+--------------->DynamicNetworkImageView{id=2131493123, res-name=courseImage, visibility=VISIBLE, width=1080, height=613, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0}
|
+--------------->ImageView{id=2131493124, res-name=playButtonImage, visibility=VISIBLE, width=168, height=169, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=456.0, y=222.0}
|
+-------------->FontTextView{id=2131493125, res-name=titleText, visibility=VISIBLE, width=936, height=166, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=72.0, y=613.0, text=40 Techniques Every Sewer Should Know, input-type=0, ime-target=false, has-links=false}
|
+-------------->FontTextView{id=2131493126, res-name=instructorText, visibility=VISIBLE, width=376, height=105, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=72.0, y=779.0, text=with Gail Yellen, input-type=0, ime-target=false, has-links=false}
|
+-------------->View{id=2131493127, res-name=horizontalLine1, visibility=VISIBLE, width=1080, height=3, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=884.0}
|
+-------------->View{id=2131493128, res-name=footer_divider, visibility=VISIBLE, width=1080, height=3, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=884.0}
|
+-------------->View{id=-1, visibility=VISIBLE, width=1080, height=18, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=887.0}
|
+---------->SwipeRefreshLayout{id=2131493218, res-name=swipe_refresh_empty_container, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}
|
+----------->CircleImageView{id=-1, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0}
|
+----------->ScrollView{id=-1, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}
|
+------------>LinearLayout{id=2131493219, res-name=not_enrolled_ui, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=4}
|
+------------->ImageView{id=2131493016, res-name=home_image, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0} ****MATCHES****
|
+------------->TextView{id=-1, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=Welcome to *****. Looks like you aren't enrolled in any classes yet., input-type=0, ime-target=false, has-links=false}
|
+------------->Button{id=2131493220, res-name=explore_****_link, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=Explore Classes, input-type=0, ime-target=false, has-links=false}
|
+------------->IconButton{id=2131493221, res-name=commercial_button, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=Play Commercial, input-type=0, ime-target=false, has-links=false}
|
+--------->FrameLayout{id=-1, visibility=VISIBLE, width=1080, height=1554, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=1080.0, y=0.0, child-count=1}
|
+---------->RecyclerView{id=2131493227, res-name=recycler_view, visibility=VISIBLE, width=1080, height=1554, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=0}
|
+------->LinearLayout{id=-1, visibility=VISIBLE, width=1080, height=1557, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}
|
+-------->ListView{id=2131493190, res-name=categoryGridView, visibility=VISIBLE, width=1080, height=1557, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=true, is-focusable=true, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=3}
|
+--------->RelativeLayout{id=-1, visibility=VISIBLE, width=1080, height=504, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=3}
|
+---------->TextView{id=2131493267, res-name=explore_text, visibility=VISIBLE, width=1080, height=168, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=Explore, input-type=0, ime-target=false, has-links=false}
|
+---------->LinearLayout{id=2131493268, res-name=linear_layout, visibility=VISIBLE, width=1080, height=168, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=168.0, child-count=2}
|
+----------->Button{id=2131493269, res-name=on_sale_button, visibility=VISIBLE, width=513, height=168, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=18.0, y=0.0, text=On Sale, input-type=0, ime-target=false, has-links=false}
|
+----------->Button{id=2131493270, res-name=free_button, visibility=VISIBLE, width=513, height=168, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=549.0, y=0.0, text=Free, input-type=0, ime-target=false, has-links=false}
|
+---------->TextView{id=2131493271, res-name=category_text, visibility=VISIBLE, width=1080, height=168, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=336.0, text=Categories, input-type=0, ime-target=false, has-links=false}
|
+--------->LinearLayout{id=-1, visibility=VISIBLE, width=1080, height=540, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=504.0, child-count=2}
|

at dalvik.system.VMStack.getThreadStackTrace(Native Method)
at Java.lang.Thread.getStackTrace(Thread.Java:579)
at Android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.Java:82)
at Android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.Java:53)
at Android.support.test.espresso.ViewInteraction.runSynchronouslyOnUiThread(ViewInteraction.Java:185)
at Android.support.test.espresso.ViewInteraction.doPerform(ViewInteraction.Java:115)
at Android.support.test.espresso.ViewInteraction.perform(ViewInteraction.Java:87)
at com.****.****.main.tests.purchase.BasePurchaseTest.testHelperSeeIfTitleInLibrary(BasePurchaseTest.Java:91)
at com.****.****.main.tests.purchase.PurchaseTests.testPurchaseIsInGallery(PurchaseTests.Java:184)
at Java.lang.reflect.Method.invokeNative(Native Method)
at Java.lang.reflect.Method.invoke(Method.Java:515)
at Android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.Java:214)
at Android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.Java:199)
at Android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.Java:192)
at junit.framework.TestCase.runBare(TestCase.Java:134)
at junit.framework.TestResult$1.protect(TestResult.Java:115)
at junit.framework.TestResult.runProtected(TestResult.Java:133)
at Android.support.test.internal.runner.junit3.DelegatingTestResult.runProtected(DelegatingTestResult.Java:90)
at junit.framework.TestResult.run(TestResult.Java:118)
at Android.support.test.internal.runner.junit3.AndroidTestResult.run(AndroidTestResult.Java:49)
at junit.framework.TestCase.run(TestCase.Java:124)
at Android.support.test.internal.runner.junit3.NonLeakyTestSuite$NonLeakyTest.run(NonLeakyTestSuite.Java:63)
at junit.framework.TestSuite.runTest(TestSuite.Java:243)
at junit.framework.TestSuite.run(TestSuite.Java:238)
at Android.support.test.internal.runner.junit3.DelegatingTestSuite.run(DelegatingTestSuite.Java:103)
at Android.support.test.internal.runner.junit3.AndroidTestSuite.run(AndroidTestSuite.Java:63)
at Android.support.test.internal.runner.junit3.JUnit38ClassRunner.run(JUnit38ClassRunner.Java:90)
at org.junit.runners.Suite.runChild(Suite.Java:128)
at org.junit.runners.Suite.runChild(Suite.Java:24)
at org.junit.runners.ParentRunner$3.run(ParentRunner.Java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.Java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.Java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.Java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.Java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.Java:300)
at org.junit.runner.JUnitCore.run(JUnitCore.Java:157)
at org.junit.runner.JUnitCore.run(JUnitCore.Java:136)
at Android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.Java:270)
at Android.app.Instrumentation$InstrumentationThread.run(Instrumentation.Java:1701)
13
StarWind0

これはEspressoのバグではありません。ビュー階層には、同じIDを持つ2つのビューが明確に表示されます。これは、ビューがAdapterViewであるViewPager内にあることが原因である可能性があります。したがって、複数のインスタンスが予想されます。

これを解決するには、ビューを一致させるときに、より具体的にします。 IDだけで行くのは役に立ちません。ホームボタンの他​​のImageViewは表示されないため、その親はGONEであるため、次のように簡単に一致させることができます。

onView(allOf(withId(..), withEffectiveVisibility(VISIBLE))).perform(click());
20
haffax

https://stackoverflow.com/a/29663042/7828429 ビューisDisplayed()をチェックするだけですべてが正常に機能します

   onView(allOf(withId(..),isDisplayed())).perform(click());
3