2016-06-15 6 views
1

IDで、私はエスプレッソでテストしていると私は、1ページ内に複数のAdapterViewsを持って、例えば:R.id.list1、R.id.list2、私はエスプレッソでリストビューを選択するには?

onDataハンドラ(withMainValue( "XX" を使用。))チェック(マッチ(isDisplayed()))

public static Matcher<Object> withMainValue(final String value) { 
    return new BoundedMatcher<Object, 
          GuessYouLikeGoodItem.DataEntity>(GuessYouLikeGoodItem.DataEntity.class) { 
     @Override public void describeTo(Description description) { 
      description.appendText("has value " + value); 
     } 
     @Override public boolean matchesSafely(
         GuessYouLikeGoodItem.DataEntity item) { 
      return item.store_name.contains(value); 
     } 
    }; 
} 

, 

エスプレッソレポート:

android.support.test.espresso.AmbiguousViewMatcherException: 'is assignable from class: class android.widget.AdapterView' matches multiple views in the hierarchy. 
    Problem views are marked with '****MATCHES****' below. 

特定のリストビューを選択して、それにonDataハンドラしようとする方法は?

答えて

2

あなたはユニークなIDを持つ複数のリストビューを持っている場合は、あなたがチェックすることができるはずですが、これはあなたが内部の要素をクリックすることができますあなたがAdapterView内に行きたい場合は

onView(withId(R.id.list1)).check(matches(isDisplayed())); 

表示されるリストの一つでありますリストビュー

onData(anything()).inAdapterView(withId(R.id.list1)).atPosition(0).perform(click()); 
+0

ありがとうございます!何かが私を救った。 – herbertD

+0

'anything()'を使うには、そのインポートが必要です: 'import static org.hamcrest.Matchers.anything;'。 – Wojtek

+0

()とは何ですか?私のテストは、「ログ」に「テストを開始しました」と表示されることはありません。あなたが理由を知っている? – Lcukerd

関連する問題