2016-08-12 54 views
8

我有一个活动,其中一些对话框处于打开状态。在这个对话框中有一个微调。我想选择在此微调特定的值,但我得到以下异常:在对话框中选择微调器时,Android espresso中的RunTimeException

java.lang.RuntimeException: Waited for the root of the view hierarchy to have window focus and not be requesting layout for over 10 seconds. If you specified a non default root matcher, it may be picking a root that never takes focus. Otherwise, something is seriously wrong. Selected Root: 
Root{[email protected], [email protected], has-window-focus=false, layout-params-type=1, layout-params-string=WM.LayoutParams{(0,0)(fillxfill) sim=#3 ty=1 fl=#1810100 wanim=0x10303e5 needsMenuKey=2}, decor-view-string=DecorView{id=-1, visibility=VISIBLE, width=1280, height=752, has-focus=true, has-focusable=true, has-window-focus=false, 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}} 
.All Roots: 
Root{[email protected], [email protected], has-window-focus=true, layout-params-type=1002, layout-params-string=WM.LayoutParams{(91,111)(509x113) gr=#10000033 sim=#1 ty=1002 fl=#1860200 fmt=-3 wanim=0x10302e3 surfaceInsets=Rect(0, 0 - 0, 0) (manual)}, decor-view-string=PopupDecorView{id=-1, visibility=VISIBLE, width=509, height=113, 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}} 
Root{[email protected], window-token=android.view.ViewRootImpl$[email protected], has-window-focus=false, layout-params-type=2, layout-params-string=WM.LayoutParams{(0,0)(wrapxwrap) gr=#11 sim=#3 ty=2 fl=#1800002 fmt=-3 wanim=0x10303e6 needsMenuKey=2}, decor-view-string=DecorView{id=-1, visibility=VISIBLE, width=616, height=490, has-focus=true, has-focusable=true, has-window-focus=false, 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}} 
Root{[email protected], [email protected], has-window-focus=false, layout-params-type=1, layout-params-string=WM.LayoutParams{(0,0)(fillxfill) sim=#3 ty=1 fl=#1810100 wanim=0x10303e5 needsMenuKey=2}, decor-view-string=DecorView{id=-1, visibility=VISIBLE, width=1280, height=752, has-focus=true, has-focusable=true, has-window-focus=false, 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}} 
at android.support.test.espresso.base.RootViewPicker.get(RootViewPicker.java:99) 
at android.support.test.espresso.ViewInteractionModule.provideRootView(ViewInteractionModule.java:69) 
at android.support.test.espresso.ViewInteractionModule_ProvideRootViewFactory.get(ViewInteractionModule_ProvideRootViewFactory.java:23) 
at android.support.test.espresso.ViewInteractionModule_ProvideRootViewFactory.get(ViewInteractionModule_ProvideRootViewFactory.java:9) 
at android.support.test.espresso.base.ViewFinderImpl.getView(ViewFinderImpl.java:68) ..... 

我的代码:

protected void selectSpinnerValue(int id, String value) { 
    onView(withId(id)).perform(click()); 
    onData(allOf(is(instanceOf(String.class)), is(value))).perform(click()); 
} 

的异常情况就行了昂达(allOf ....)

我该如何告诉espresso查看对话框?

+0

尝试使用isPlatformPopup(),它会匹配微调器呈现的窗口 – jeprubio

+0

谢谢你,我怎么用这个? onData(isPlatformPopup(allOf(is(instanceOf(String.class)))))不起作用 – Peter

+1

我正在从我的手机写信,我认为onData正常,espresso在执行onView代码时抛出异常例如:onView(withId(id))。inRoot(isPlattormPopup())。perform(click());应该管用。试试看,我以前看到过这个例外。 – jeprubio

回答

4

试试这个:

onData(allOf(is(instanceOf(String.class)), is(value))) 
    .inRoot(isPlatformPopup()).perform(click()); 
6

我有同样的错误,当我试图将项目的对话片段内部的离心器相匹配。 这有助于:

onView(withText(value)).inRoot(isPlatformPopup()).perform(click()); 
+0

哇,非常感谢!那正是我的问题 –

相关问题