2017-03-17 13 views
1

RecylerViewには最後にテキストビューが含まれています。私はrecylerviewを表示する最後のテキストにスクロールできません。私には見つかりましたが、解決策を見つけることができませんでした。私はを試してみましたRecylerViewはエスプレッソのアンドロイドテストケースの最後のテキストにスクロールしません

コード: -

1. onView(withId(R.id.recylerview)).perform(scrollToPosition(13)); 
//my last text view in recyler view is at position 13 
2.onView(withText("Some content")).perform(scrollTo(), click()); 
//my text is "Some content" 

私の問題は、リサイクルビューiは、プログラムのテキスト値を設定しているすべての13 items.Asに同じテキストビューが含まれているとして、私は、IDとそれを検索することができないということです。あなたは、あなたのテストにthis RecyclerViewMatcherファイルを追加することができ

onView(withId(R.id.txtview)).perform(scrollTo(), click()); 

EspressoCode

UiObject2 button9 = device.findObject(By.text("S 5 [None]")); 
     button9.click(); 
     try { 
      UiObject srText = new UiObject(new UiSelector().resourceId("com.example.project:id/radio")); 
      sText.click(); 

     }catch(Exception e){ 

     } 
     onView(withRecyclerView(R.id.recylerview).atPosition(13)) 
       .check(matches((hasDescendant(withText("Some content"))))); 

     UiObject2 button10 = device.findObject(By.text("S 6 [None]")); 
     button10.click(); 
     try { 
      UiObject sensorText = new UiObject(new UiSelector().resourceId("com.example.project:id/radio")); 
      sensorText.click(); 

     }catch(Exception e){ 

     } 

答えて

0

- :

だから、このコード を適用することはできません。あなたは

public static RecyclerViewMatcher withRecyclerView(final int recyclerViewId) { 
     return new RecyclerViewMatcher(recyclerViewId); 
    } 

にそれを使用し、最終的にだからあなたのエスプレッソファイルが...

public class YouEspressoTest { 

    public static RecyclerViewMatcher withRecyclerView(final int recyclerViewId) { 
     return new RecyclerViewMatcher(recyclerViewId); 
    } 

    @Before 
    public void setUp() { 
     ... 
    } 

    @Test 
    public void testRecyclerView() { 
     ... 
     onView(withRecyclerView(R.id.recyclerview).atPosition(13)) 
       .check(matches((hasDescendant(withText("Some content"))))); 
     ... 
    } 
} 
+0

ようになり

onView(withRecyclerView(R.id.recyclerview).atPosition(13)) .check(matches((hasDescendant(withText("Some content"))))); 

を行うことができますので、その後ねえ、私はあなたのエスプレッソのテストに、このメソッドを追加これを実装しようとしましたが、withRecyclerViewとatPositionメソッドshowメソッドを解決できません。 –

+0

基本的には、androidTest/java/blahblahフォルダにRecyclerViewMatcherファイル(ファイルとして)が必要です。次に、実際のエスプレッソ・テストの中で、withRecyclerView静的メソッドを追加する必要があります。 atPositionメソッドはRecyclerViewMatcher内のパブリックメソッドなので、一度アクセスすれば問題ありません。 –

+0

はい、私は実装しましたが、まだ動作していません。デバッガが到達すると、アプリケーションはプロセスの再開に近づきます。 –

関連する問題