Table of contents

  1. Actions
  2. Custom Actions
  3. Custom Matcher
  4. RecyclerView 특정 위치 ViewHolder 의 View check 방법

Actions

drawer 열고 닫기

// Close Drawer to click on navigation.
onView(withId(R.id.drawerLayout))
  .check(matches(DrawerMatchers.isOpen())) // Left Drawer should be closed.
  .perform(DrawerActions.close()); // Open Drawer

Bottom nav 선택하기

val navTask = onView(allOf(withId(R.id.navigation_tasks), isDisplayed()))
navTask.perform(click())

Custom Actions

Custom Matcher

BottomNav Item 의 selected 상태 확인

buttonHome.check(matches(withBottomNavItemCheckedStatus(false)))

RecyclerView 특정 위치 ViewHolder 의 View check 방법

holder.itemView 에 tag 에 position 을 넣어두면 viewQuery 에서 사용 할 수 있다

onView(
  allOf(
    withId(R.id.task_item_empty),
    withParent(withTagValue(`is`(position))),
    withParent(withParent(withId(R.id.task_list))),
    isDisplayed()
  )
).check(matches(isDisplayed()))
override fun onBindViewHolder(holder: TaskRecyclerView.ViewHolder, position: Int) {
  holder.onBind(position)
  if (BuildConfig.DEBUG) {
    holder.itemView.setTag(position)
  }
}