Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. @Rule
  2. public final ActivityTestRule<YourActivity> mActivityRule = new ActivityTestRule<>(YourActivity.class);
  3.  
  4. @Test
  5. public void testSample(){
  6. if (getRVcount() > 0){
  7. onView(withId(R.id.our_recycler_view)).perform(RecyclerViewActions.actionOnItemAtPosition(0, click()));
  8. }
  9. }
  10.  
  11. private int getRVcount(){
  12. RecyclerView recyclerView = (RecyclerView) mActivityRule.getActivity().findViewById(R.id.our_recycler_view);
  13. return recyclerView.getAdapter().getItemCount();
  14. }
  15.  
  16. @Test
  17. fun mainActivityTest() {
  18. val yourRecycler = onView(
  19. allOf(
  20.  
  21. childAtPosition(
  22. withClassName(`is`("androidx.constraintlayout.widget.ConstraintLayout")),
  23. 0
  24. ),
  25. instanceOf(RecyclerView::class.java)
  26. )
  27. )
  28. yourRecycler.check { view, noViewFoundException ->
  29. noViewFoundException?.apply {
  30. throw this
  31. }
  32. assertTrue(view is RecyclerView &&
  33. view.adapter != null && view.adapter?.itemCount?:-1 > 0
  34. )
  35.  
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement