2017-02-07 5 views
1

J'ai un tableau de bord avec des vues personnalisées.Afficher la vue dans la hiérarchie avec Android Espresso

Je veux tester qu'une fois que les données sont disponibles, elles s'affichent correctement dans les différents affichages de texte.

Mon problème est: comment puis-je sélectionner les différents TextViews étant donné qu'ils appartiennent à une hiérarchie.

Exemple: comment obtenir current_month > sales > value view?

Je sais seulement comment faire avec un seul niveau de hiérarchie, mais cela ne suffit pas ici:

onView(
    allOf(withId(R.id.value), 
    isDescendantOfA(withId(R.id.current_month)))) 

La hiérarchie ressemble:

+- 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) 

Répondre

2

Ok. Regarde plutôt simple.

onView(allOf(withId(R.id.value), 
      isDescendantOfA(allOf(withId(R.id.sales), 
        isDescendantOfA(withId(R.id.current_month)))))) 

Est-ce la meilleure façon?

0

Utiliser withParent(Matcher) Hiérarchie Voir matcher:

onView(allOf(withId(R.id.value), 
    withParent(allOf(withId(R.id.sales), 
      withParent(withId(R.id.current_month)))), 
    isDisplayed())); 

Hope this helps.