2017-03-21 3 views
0

私のアンドロイド計測器テストでは、ページビューから外れているリサイクルビューをタップしようとしています。この要素にスクロールして、それをタップしたいと思います。私はこれを行うとき、私は、コードリサイクラビューでscrollToを使用しているエラーエスプレッソアンドロイドテスト

onView(allOf(withId(R.id.offerSummaryLayout), hasDescendant(withText("Online deal")), FirstViewMatcher.firstView())).perform(scrollTo(), click()); 

を書かれている

は、しかしそれは、このエラー android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: (with id: uk.co.myAPP.android.beta:id/offerSummaryLayout and has descendant: with text: is "Online sale" and is the first view that comes along) 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{3395c7d VFED.VC.. .F...... 0,120-768,700 #7f1000b9 app:id/main_categories_grid_view}

は、他の誰がこの問題をexpereincedか、私は

+0

として使用できます。[RecyclerViewActions](https://developer.android.com/reference/android/support/test/espresso/contrib/RecyclerViewActions.html)を利用してください。 – azizbekian

+0

クリックしたいアイテムが表示されていないので、次のようなことをしたい場合があります:onView(withId(recyclerViewId))。perform(scrollToPosition(position)); –

+0

Visual Studioを使用していますか?そうでない場合は、質問から "coded-ui-tests"タグを削除してください。 – AdrianHHH

答えて

0

定義を使用することができます解像度を持っていますスローカスタムマッチャー:

private <View> Matcher<View> first(final Matcher<View> matcher) { 
    return new BaseMatcher<View>() { 
     boolean isFirst = true; 

     @Override 
     public boolean matches(final Object item) { 
      if (isFirst && matcher.matches(item)) { 
       isFirst = false; 
       return true; 
      } 

      return false; 
     } 

     @Override 
     public void describeTo(final Description description) { 
      description.appendText("should return first matching item"); 
     } 
    }; 
} 

それから、OnView(allOf(withId(R.id.offerSummaryLayout)).perform(RecyclerViewActions.actionOnItem(first(hasDescendant(withText("Online deal"))),click()));

+0

これは、これに一致するすべてのものを選択します。最初に見つかったものだけをタップする必要があります。 –

+0

- onView(allOf(withId(R.id.offerSummaryLayout)))への回答を編集しました。(RecyclerViewActions.actionOnItem(Matchers。 –

+0

@BillyBoyo私の答えが正しい答えとしてu、upvote、markを助けてくれたのですか? –

関連する問題