Issue
To verify a text string for an item in a RV I use
private fun verifyItemName(pos: Int, name: String) =
onView(
RecyclerViewMatcher(R.id.recycler_view)
.atPositionOnView(pos, R.id.text_view)
).check(matches(withText(name)))
Where RecyclerViewMatcher
from here is
class RecyclerViewMatcher(private val recyclerViewId: Int) {
fun atPosition(position: Int): Matcher<View> {
return atPositionOnView(position, -1)
}
fun atPositionOnView(position: Int, targetViewId: Int): Matcher<View> {
return object : TypeSafeMatcher<View>() {
var resources: Resources? = null
var childView: View? = null
override fun describeTo(description: Description) {
var idDescription = recyclerViewId.toString()
if (this.resources != null) {
idDescription = try {
this.resources!!.getResourceName(recyclerViewId)
} catch (var4: Resources.NotFoundException) {
"$recyclerViewId (resource name not found)"
}
}
description.appendText("RecyclerView with id: $idDescription at position: $position")
}
public override fun matchesSafely(view: View): Boolean {
this.resources = view.resources
if (childView == null) {
val recyclerView = view.rootView.findViewById<RecyclerView>(recyclerViewId)
if (recyclerView?.id == recyclerViewId) {
val viewHolder = recyclerView.findViewHolderForAdapterPosition(position)
childView = viewHolder?.itemView
} else {
return false
}
}
return if (targetViewId == -1) {
view === childView
} else {
val targetView = childView?.findViewById<View>(targetViewId)
view === targetView
}
}
}
}
}
but how can I long press an item in the rv?
Solution
Found it
onView(
RecyclerViewMatcher(R.id.rv_list)
.atPositionOnView(0, R.id.iv_direction)
).perform(longClick())
Answered By - the_prole
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.