2017-02-07 11 views
1

私はカスタムビューを持つダッシュボードを持っています。Androidのエスプレッソで階層内のビューを検索

データが利用可能になると、さまざまなテキストビューに適切に表示されることをテストします。

私の問題は、階層に属するさまざまなTextViewを選択する方法です。

例:入手方法current_month > sales > value view

私は、単一の階層レベルをどうするだけ方法を知っているが、それはここでは解決しない:

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

階層は次のようになります。

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

答えて

2

[OK]をクリックします。かなりシンプルに見えます。

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

これが最善の方法ですか?

0

使用withParent(Matcher)階層ビューのMatcher:

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

・ホープ、このことができます。

関連する問題