在对话框中选择微调器时,Android espresso中出现RunTimeException [英] RunTimeException in Android espresso when selecting spinner in dialog

查看:65
本文介绍了在对话框中选择微调器时,Android espresso中出现RunTimeException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个活动,其中一些对话框是开放式的.在此对话框上有一个微调器.我想在此微调器中选择一个特定的值,但是出现以下异常:

I have an activity where some dialog is openend. On this dialog there is a spinner. I want to select a specific value in this spinner, but I get following exception:

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{application-window-token=android.view.ViewRootImpl$W@7017bc1, window-token=android.view.ViewRootImpl$W@7017bc1, 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{application-window-token=android.view.ViewRootImpl$W@ae6d4cb, window-token=android.view.ViewRootImpl$W@920a4a8, 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{application-window-token=android.view.ViewRootImpl$W@ae6d4cb, window-token=android.view.ViewRootImpl$W@ae6d4cb, 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{application-window-token=android.view.ViewRootImpl$W@7017bc1, window-token=android.view.ViewRootImpl$W@7017bc1, 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());
}

异常发生在onData(allOf ....)

The exception happens on the line onData(allOf....)

如何告诉espresso在对话框中查看?

How can I tell espresso to look in the dialog?

推荐答案

当我尝试匹配对话框片段中微调器中的项目时,我遇到了相同的错误. 这有助于:

I had the same error when I tried to match an item inside a spinner inside a dialog-fragment. This helped:

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

这篇关于在对话框中选择微调器时,Android espresso中出现RunTimeException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆