2015-01-21 20 views
16

Aşağıdakileri yapmayı denedim: onView (allOf (withId (R.id.single_row_text), withText ("Item1"))) (tıklatın());Espresso - tek bir listeyi görüntülemek için tıklayın

Ama elimdeki tek geçerli:

android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: (with id: net.test.android:id/single_row_text and with text: is "Item1") 
If the target view is not part of the view hierarchy, you may need to use Espresso.onData to load it from one of the following AdapterViews:[email protected] 

View Hierarchy: 
+>DecorView{id=-1, visibility=VISIBLE, width=480, height=800, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1} 
| 
+->LinearLayout{id=-1, visibility=VISIBLE, width=480, height=800, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=3} 
| 
+-->ActionBarContainer{id=16909032, res-name=action_bar_container, visibility=VISIBLE, width=480, height=48, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=48.0, child-count=2} 
| 
+--->ActionBarView{id=16909033, res-name=action_bar, visibility=VISIBLE, width=480, height=48, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=3} 
| 
+---->LinearLayout{id=-1, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=true, is-enabled=false, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2} 
| 
+----->ImageView{id=16908838, res-name=up, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0} 
| 
+----->LinearLayout{id=-1, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2} 
| 
+------>TextView{id=16908845, res-name=action_bar_title, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=, input-type=0, ime-target=false, has-links=false} 
| 
+------>TextView{id=16908846, res-name=action_bar_subtitle, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=, input-type=0, ime-target=false, has-links=false} 
| 
+---->HomeView{id=-1, visibility=VISIBLE, width=127, height=48, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=true, is-enabled=false, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=19.0, y=0.0, child-count=2} 
| 
+----->ImageView{id=16908838, res-name=up, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0} 
| 
+----->ImageView{id=16908332, res-name=home, visibility=VISIBLE, width=119, height=25, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=4.0, y=12.0} 
| 
+---->ActionMenuView{id=-1, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=480.0, y=24.0, child-count=0} 
| 
+--->ActionBarContextView{id=16909034, res-name=action_context_bar, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=0} 
| 
+-->FrameLayout{id=16908290, res-name=content, visibility=VISIBLE, width=480, height=704, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=96.0, child-count=1} 
| 
+--->CustomDrawerLayout{id=2131362153, res-name=main_frame, visibility=VISIBLE, width=480, height=704, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=true, is-focusable=true, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2} 
| 
+---->FrameLayout{id=2131362154, res-name=main_content_frame, visibility=VISIBLE, width=480, height=704, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=0} 
| 
+---->NoSaveStateFrameLayout{id=2131362155, res-name=menu_fragment, visibility=VISIBLE, width=260, height=704, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1} 
| 
+----->LinearLayout{id=-1, visibility=VISIBLE, width=260, height=704, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2} 
| 
+------>View{id=-1, visibility=VISIBLE, width=260, height=1, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0} 
| 
+------>ListView{id=2131362159, res-name=browse_types_list, visibility=VISIBLE, width=260, height=703, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=1.0, child-count=0} 
| 
+-->ActionBarContainer{id=16909035, res-name=split_action_bar, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=0} 

Ben de onData bir sürü şey denedik ama hepsi başarısız şunlardır: Bunun

onData(allOf(is(AnyTextView.class), withText("Item1"))).perform(click()); 
onData(Matchers.allOf(Matchers.is(Matchers.instanceOf(ListView.class)), Matchers.hasToString(Matchers.startsWith("Item1")))).perform(ViewActions.click()); 
onData(anything()).inAdapterView(withContentDescription("menu_item_icon")).atPosition(0).perform(click()); 
onData(hasToString(startsWith("Item1"))) 
       .inAdapterView(withId(R.id.browse_types_list)) 
       .perform(click()); 

herhangi bir öneriniz? Teşekkürler!

ÇÖZÜMLER (Güncellendi)

Bu bir zamanlama sorunu olarak çıkıyor. Testi yürütmeden önce Thread.sleep (5000) çalıştırıyorum ve işe yaradı.

cevap

44

Bunu deneyin.

onData(anything()).inAdapterView(withId(R.id.list_view)).atPosition(0).perform(click()); 
+0

Bunu da denedim. Ancak bir zamanlama sorunu olduğu ortaya çıkıyor. Testi yürütmeden önce Thread.sleep (5000) çalıştırıyorum ve işe yaradı. –

+0

Espresso, tüm kullanıcı arayüzü zamanlamalarını ele almayı amaçlamaktadır. Liste görüntülemeden önce bazı veri yüklemesi var mı? –

+0

evet emin, bu yüzden bu yürüyüş ile geldi, ama hala thread.sleep –

8

Espresso'nun güzelliği, tüm bu 'zamanaşımı' karmaşasıyla uğraşmıyor.

Pencere animasyonu ölçeği

Geçiş animasyonu ölçeği: Geliştirici seçenekleri Aşağıdaki 3 ayarları devre dışı> Ayarlar- altında Cihazınızda

: Espresso belgelerinde belirtildiği gibi

size engelli animasyonlar var

Animatör süresi ölçeği

?

+1

Bu çözüm sorunlarımı çözdü. Teşekkür ederim!! : D –

+0

Ve NO Zaman Aşımları diyebiliriz? – Morozov

İlgili konular