2016-05-10 1 views
2

У нас есть страница, которая в некотором смысле действует как электронная почта. Итак, у нас есть Recyclerview с кучей TextViews, один из которых - большой TextView, содержащий все содержимое электронной почты.Неоднозначные результаты Эспрессо на довольно базовом испытании

Итак, мы просто пытаемся проверить, что весь текст электронной почты загружен и отображен (мы добавляем специальную строку в конце, и мы собираемся проверить, что она появляется).

Espresso.onView(Matchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withId(R.id.email_content))) 
      .perform(ViewActions.scrollTo(), ViewActions.swipeUp()); 

Когда побежал мы получаем эту ошибку:

Caused by: android.support.test.espresso.PerformException: Error performing 'click (after 3 attempts)' on view 'unknown'. 
at android.support.test.espresso.PerformException$Builder.build(PerformException.java:83) 
at android.support.test.espresso.action.MotionEvents.sendDown(MotionEvents.java:111) 
at android.support.test.espresso.action.Swipe.sendLinearSwipe(Swipe.java:88) 
at android.support.test.espresso.action.Swipe.access$100(Swipe.java:31) 
at android.support.test.espresso.action.Swipe$1.sendSwipe(Swipe.java:38) 
at android.support.test.espresso.action.GeneralSwipeAction.perform(GeneralSwipeAction.java:70) 

Так что, когда мы изменить его к этому:

Espresso.onView(Matchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withId(R.id.email_content))) 
      .perform(ViewActions.swipeUp()); 

Мы получаем эту ошибку:

Caused by: java.lang.RuntimeException: Action will not be performed because the target view does not match one or more of the following constraints: 
at least 90 percent of the view's area is displayed to the user. 
Target view: "AppCompatTextView{id=2131558822, res-name=email_content, visibility=VISIBLE, width=1048, height=1513896, 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=16.0, y=175.0, text= 

Почему в первом случае он говорит, что не мог прокрутить vi ew, а во втором случае он говорит, что он недостаточно хорошо виден?

ответ

1

ViewActions.scrollTo() не может использоваться с RecyclerView, поскольку scrollTo требует работы только с объектами, унаследованными от ScrollView. Чтобы прокрутить необходимый пункт в RecyclerView, вы должны написать свой собственный ViewAction. Вы можете посмотреть, как сделать этот метод here см scrollToPosition

0

Когда я использую swipeDown() это было нормально, но swipeUp() производится точно такая же ошибка:

Caused by: android.support.test.espresso.PerformException: Error performing 'click (after 3 attempts)' on view 'unknown'. 

Я пытался имитировать/проверить салфетки на ресайклере в фрагменте. Он будет извлекать новые данные с сервера, поскольку он пропускает 60% количества элементов в представлении recycler.

Android Studio 2.3.1

Windows 7

Genymotion Samsung S6

Мое временное решение для имитации поведения делается ниже. Надеюсь, это поможет кому-то с таким же поведением и ошибкой.

MyFragment.java

 ... 
     public void onScrolled(RecyclerView recyclerView, int dx, int dy) { 
      super.onScrolled(recyclerView, dx, dy); 

      ... 
      else if(mainActivity.isAutomatedTesting && dy < 0) //check for scroll up. isAutomatedTesting is set to true in MyTest.java 
      { 
       visibleItemCount = mLayoutManager.getChildCount(); 
       totalItemCount = mLayoutManager.getItemCount(); 
       pastVisiblesItems = mLayoutManager.findFirstVisibleItemPosition(); 
       lastVisibleItemPos = mLayoutManager.findLastCompletelyVisibleItemPosition(); 

       if (loading) 
       { 
        if ((lastVisibleItemPos/totalItemCount) >= listTolerance) 
        {        
         //fetch new data 
        } 
       } 
      } 
      ... 

MyTest.java

 //wait for first lot of data to finish loading 
     try { 
      Thread.sleep(6000); 
     } catch (InterruptedException e) { 
      e.printStackTrace(); 
     } 

     int count = 1; 
     int maxCount = 4; 
     while(count < maxCount) { 

      onView(withId(R.id.recycler_view)) 
        .perform(RecyclerViewActions.scrollToPosition(count * 9)); 
      onView(withId(R.id.recycler_view)) 
        .perform(swipeDown()); 

      try { 
       Thread.sleep(15000); 
      } catch (InterruptedException e) { 
       e.printStackTrace(); 
      } 

      count++; 
     }