这个错误 "Caused by: java.lang.RuntimeException: Found more than one sub-view matching holder with view: has descendant: with id:" 是什么意思?
What does this error "Caused by: java.lang.RuntimeException: Found more than one sub-view matching holder with view: has descendant: with id:" mean?
我正在使用 espresso 来测试一个带有 recyclerview 的 Android 应用程序,并且当方法
onView(withId(R.id.playing_recycler)).perform(scrollTo(hasDescendant(withId(R.id.header))));
被调用。
整个错误在这里:
android.support.test.espresso.PerformException: Error performing 'scroll RecyclerView to: holder with view: has descendant: with id: com.refactor:id/header' on view 'with id: com.refactor:id/playing_recycler'.
at android.support.test.espresso.PerformException$Builder.build(PerformException.java:83)
at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:80)
at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:56)
at android.support.test.espresso.ViewInteraction.runSynchronouslyOnUiThread(ViewInteraction.java:184)
at android.support.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:115)
at android.support.test.espresso.ViewInteraction.perform(ViewInteraction.java:87)
at com.ui.home.nowplaying.BaseNowPlayingFragmentEspressoTest.checkNowPlayingMoreLikeThisDoesExist(BaseNowPlayingFragmentEspressoTest.java:197)
at com.ui.home.playing.LikeThisTest.testThisIsDisplayed(LikeThisTest.java:37)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at android.support.test.internal.statement.UiThreadStatement.evaluate(UiThreadStatement.java:55)
at com.test.base.DelayedFinishActivityTestRule$DelayedFinishActivityTestStatement.evaluate(DelayedFinishActivityTestRule.java:226)
at android.support.test.rule.ServiceTestRule$ServiceStatement.evaluate(ServiceTestRule.java:329)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access[=11=]0(ParentRunner.java:58)
at org.junit.runners.ParentRunner.evaluate(ParentRunner.java:268)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access[=11=]0(ParentRunner.java:58)
at org.junit.runners.ParentRunner.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:262)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1996)
Caused by: java.lang.RuntimeException: Found more than one sub-view matching holder with view: has descendant: with id: com.refactor:id/header
*** Matched ViewHolder item at position: 2 ***
View Hierarchy:
+>PercentRelativeLayout{id=-1, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=true, has-window-focus=false, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=true, has-input-connection=false, x=0.0, y=0.0, child-count=1}
|
+->TypeFaceTextView{id=2131690060, res-name=more_like_this_header, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=true, has-window-focus=false, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=true, is-selected=false, root-is-layout-requested=true, has-input-connection=false, x=0.0, y=0.0, text=More like this, input-type=0, ime-target=false, has-links=false}
|
*** Matched ViewHolder item at position: 7 ***
View Hierarchy:
+>PercentRelativeLayout{id=-1, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=true, has-window-focus=false, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=true, has-input-connection=false, x=0.0, y=0.0, child-count=1}
|
+->TypeFaceTextView{id=2131690060, res-name=more_like_this_header, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=true, has-window-focus=false, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=true, is-selected=false, root-is-layout-requested=true, has-input-connection=false, x=0.0, y=0.0, text=More like this, input-type=0, ime-target=false, has-links=false}
|
at android.support.test.espresso.contrib.RecyclerViewActions$ScrollToViewAction.perform(RecyclerViewActions.java:361)
at android.support.test.espresso.ViewInteraction.run(ViewInteraction.java:144)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:168)
at android.app.ActivityThread.main(ActivityThread.java:5885)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
你应该覆盖
getItemId(int 位置)
并确保您的 ID 是唯一的
你检查过你的键盘配置了吗?您应该将键盘设置为英语并禁用滑动
我遇到了这个问题,我解决它的唯一方法是拥有一个可以 select 只找到一个视图的自定义匹配器。您的错误表明匹配器找到了多个视图,因此浓缩咖啡无法做出决定。试试这个:
public static Matcher<View> withIndex(final Matcher<View> matcher, final int index) {
return new TypeSafeMatcher<View>() {
int currentIndex = 0;
@Override
public void describeTo(Description description) {
description.appendText("with index: ");
description.appendValue(index);
matcher.describeTo(description);
}
@Override
public boolean matchesSafely(View view) {
return matcher.matches(view) && currentIndex++ == index;
}
};
}
然后你可以这样称呼它:
Matcher<View> matcher = allOf(withIndex(withId(R.id.myview),1));
onView(matcher).perform(click());
特别感谢匹配器的作者。
我正在使用 espresso 来测试一个带有 recyclerview 的 Android 应用程序,并且当方法
onView(withId(R.id.playing_recycler)).perform(scrollTo(hasDescendant(withId(R.id.header))));
被调用。
整个错误在这里:
android.support.test.espresso.PerformException: Error performing 'scroll RecyclerView to: holder with view: has descendant: with id: com.refactor:id/header' on view 'with id: com.refactor:id/playing_recycler'.
at android.support.test.espresso.PerformException$Builder.build(PerformException.java:83)
at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:80)
at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:56)
at android.support.test.espresso.ViewInteraction.runSynchronouslyOnUiThread(ViewInteraction.java:184)
at android.support.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:115)
at android.support.test.espresso.ViewInteraction.perform(ViewInteraction.java:87)
at com.ui.home.nowplaying.BaseNowPlayingFragmentEspressoTest.checkNowPlayingMoreLikeThisDoesExist(BaseNowPlayingFragmentEspressoTest.java:197)
at com.ui.home.playing.LikeThisTest.testThisIsDisplayed(LikeThisTest.java:37)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at android.support.test.internal.statement.UiThreadStatement.evaluate(UiThreadStatement.java:55)
at com.test.base.DelayedFinishActivityTestRule$DelayedFinishActivityTestStatement.evaluate(DelayedFinishActivityTestRule.java:226)
at android.support.test.rule.ServiceTestRule$ServiceStatement.evaluate(ServiceTestRule.java:329)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access[=11=]0(ParentRunner.java:58)
at org.junit.runners.ParentRunner.evaluate(ParentRunner.java:268)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access[=11=]0(ParentRunner.java:58)
at org.junit.runners.ParentRunner.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:262)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1996)
Caused by: java.lang.RuntimeException: Found more than one sub-view matching holder with view: has descendant: with id: com.refactor:id/header
*** Matched ViewHolder item at position: 2 ***
View Hierarchy:
+>PercentRelativeLayout{id=-1, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=true, has-window-focus=false, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=true, has-input-connection=false, x=0.0, y=0.0, child-count=1}
|
+->TypeFaceTextView{id=2131690060, res-name=more_like_this_header, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=true, has-window-focus=false, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=true, is-selected=false, root-is-layout-requested=true, has-input-connection=false, x=0.0, y=0.0, text=More like this, input-type=0, ime-target=false, has-links=false}
|
*** Matched ViewHolder item at position: 7 ***
View Hierarchy:
+>PercentRelativeLayout{id=-1, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=true, has-window-focus=false, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=true, has-input-connection=false, x=0.0, y=0.0, child-count=1}
|
+->TypeFaceTextView{id=2131690060, res-name=more_like_this_header, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=true, has-window-focus=false, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=true, is-selected=false, root-is-layout-requested=true, has-input-connection=false, x=0.0, y=0.0, text=More like this, input-type=0, ime-target=false, has-links=false}
|
at android.support.test.espresso.contrib.RecyclerViewActions$ScrollToViewAction.perform(RecyclerViewActions.java:361)
at android.support.test.espresso.ViewInteraction.run(ViewInteraction.java:144)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:168)
at android.app.ActivityThread.main(ActivityThread.java:5885)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
你应该覆盖 getItemId(int 位置) 并确保您的 ID 是唯一的
你检查过你的键盘配置了吗?您应该将键盘设置为英语并禁用滑动
我遇到了这个问题,我解决它的唯一方法是拥有一个可以 select 只找到一个视图的自定义匹配器。您的错误表明匹配器找到了多个视图,因此浓缩咖啡无法做出决定。试试这个:
public static Matcher<View> withIndex(final Matcher<View> matcher, final int index) {
return new TypeSafeMatcher<View>() {
int currentIndex = 0;
@Override
public void describeTo(Description description) {
description.appendText("with index: ");
description.appendValue(index);
matcher.describeTo(description);
}
@Override
public boolean matchesSafely(View view) {
return matcher.matches(view) && currentIndex++ == index;
}
};
}
然后你可以这样称呼它:
Matcher<View> matcher = allOf(withIndex(withId(R.id.myview),1));
onView(matcher).perform(click());
特别感谢匹配器的作者。