Issue
I have a dashboard with custom views.
I want to test that once the data is available, it properly gets displayed in the various text views.
My problem is: how do I select the various TextViews given they belong to a hierarchy.
Example: how to get current_month > sales > value view
?
I know only how to do with a single hierarchy level but that does not help here:
onView(
allOf(withId(R.id.value),
isDescendantOfA(withId(R.id.current_month))))
The hierarchy looks like:
+- RelativeLayout
|
|___+ CustomCardView (id = current_month)
| |
| |___+ CustomValueView (id = sales)
| | |
| | |___+ TextView (id = value)
| | |
| | |___+ TextView (id = unit)
| |
| |___+ CustomValueView (id = earnings)
| |
| |___+ TextView (id = value)
| |
| |___+ TextView (id = unit)
|
|___+ CustomCardView (id = last_month)
| |
| |___+ CustomValueView (id = sales)
| | |
| | |___+ TextView (id = value)
| | |
| | |___+ TextView (id = unit)
| |
| |___+ CustomValueView (id = earnings)
| |
| |___+ TextView (id = value)
| |
| |___+ TextView (id = unit)
|
|___+ CustomCardView (id = all_time)
|
|___+ CustomValueView (id = sales)
| |
| |___+ TextView (id = value)
| |
| |___+ TextView (id = unit)
|
|___+ CustomValueView (id = earnings)
|
|___+ TextView (id = value)
|
|___+ TextView (id = unit)
Solution
Ok. Looks rather simple.
onView(allOf(withId(R.id.value),
isDescendantOfA(allOf(withId(R.id.sales),
isDescendantOfA(withId(R.id.current_month))))))
Is that the best way?
Answered By - Vincent Mimoun-Prat
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.