Q:

Espresso: Clicking on Recycler view with unknown position

I Have Have a list if recycler views in different positions in screen.
 Like below 

I want to click on specific recycler view based on the variable text 'Job#' Inside it.
But cannot perform the same as I do not know the exact position I should click.
The position of recycler view keeps changing. Tried below code but it clicks on static position '6'
recyclerView = onView(
            allOf(withId(R.id.recycler_view), isDisplayed()));
    recyclerView.perform(actionOnItemAtPosition(6, click()));

I want to know the proper position dynamically.

A:

Clicking the position in instrumentation tests, in my opinion, is a bad practice as it leads to non-deterministic tests. This is applicable to both RecyclerView and AdapterView.
So in order to not rely on a position you need an itemView matcher for your recyclerview action.
ItemView matcher is a view matcher that matches the itemview of the ViewHolder. In your case you need to match a LinearLayout that holds the highlighted RelativeLayout, which can be represented as hasDescendant(withText("Job 109"))
The end solution in your case should look like:
onView(allOf(withId(R.id.recycler_view),isDisplayed())).perform(Recyclerview actions.actionOnItem(hasDescendant(withText("Job 109")), click()));

