【发布时间】:2018-06-12 15:09:52
【问题描述】:
我正在尝试使用 Espresso 从列表中选择一个项目。
应该很简单,但我需要选择一个有多个条件的项目。
条件是:
task.getLocation != null; task.getCurrentStatus == Task.ASSIGNED;
所以使用 atPosition() 是行不通的。列表中的项目不断变化。
我的悲伤尝试:
onData(new BoundedMatcher<Object, Task>(Task.class) {
@Override
protected boolean matchesSafely(Task item) {
return (item.getLocation() != null && item.getCurrentStatus() == Task.ASSIGNED);
}
@Override
public void describeTo(Description description) {
}
}).inAdapterView(withId(R.id.listView)).perform(click());
我从 Dinesh VG 的回答中得到它:
Espresso onData perform click on multiple items
但是,如果我使用完整的给定示例,它就不起作用。它不接受 allOf() 也不接受 is()。
我也尝试了其他方法,非常不成功。
堆栈跟踪:
android.support.test.espresso.PerformException: Error performing 'load adapter data' on view 'Animations or transitions are enabled on the target device.
For more info check: -------
with id: com.sentilant.driviantasks:id/listView'.
at android.support.test.espresso.PerformException$Builder.build(PerformException.java:82)
at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:79)
at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:51)
at android.support.test.espresso.ViewInteraction.waitForAndHandleInteractionResults(ViewInteraction.java:312)
at android.support.test.espresso.ViewInteraction.desugaredPerform(ViewInteraction.java:173)
at android.support.test.espresso.ViewInteraction.perform(ViewInteraction.java:114)
at android.support.test.espresso.DataInteraction$DisplayDataMatcher$1.apply(DataInteraction.java:213)
at android.support.test.espresso.DataInteraction$DisplayDataMatcher$1.apply(DataInteraction.java:210)
at android.support.test.espresso.DataInteraction$DisplayDataMatcher.<init>(DataInteraction.java:230)
at android.support.test.espresso.DataInteraction$DisplayDataMatcher.<init>(DataInteraction.java:205)
at android.support.test.espresso.DataInteraction$DisplayDataMatcher.displayDataMatcher(DataInteraction.java:248)
at android.support.test.espresso.DataInteraction.makeTargetMatcher(DataInteraction.java:150)
at android.support.test.espresso.DataInteraction.perform(DataInteraction.java:135)
at com.sentilant.driviantasks.TestMapMasterUI.testLayoutWithTask(TestMapMasterUI.java:201)
at com.sentilant.driviantasks.TestMapMasterUI.NavigationLayoutTests(TestMapMasterUI.java:73)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.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 android.support.test.internal.statement.UiThreadStatement.evaluate(UiThreadStatement.java:55)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:270)
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$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at android.support.test.runner.AndroidJUnit4.run(AndroidJUnit4.java:101)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.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:56)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:384)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2082)
Caused by: java.lang.RuntimeException: Multiple data elements matched: . Elements: [Data: com.sentilant.driviantasks.api.task.Task@bb69b92 (class: com.sentilant.driviantasks.api.task.Task) token: 17, Data: com.sentilant.driviantasks.api.task.Task@61edede (class: com.sentilant.driviantasks.api.task.Task) token: 18]
at android.support.test.espresso.action.AdapterDataLoaderAction.perform(AdapterDataLoaderAction.java:125)
at android.support.test.espresso.ViewInteraction$SingleExecutionViewAction.perform(ViewInteraction.java:356)
at android.support.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:248)
at android.support.test.espresso.ViewInteraction.access$100(ViewInteraction.java:63)
at android.support.test.espresso.ViewInteraction$1.call(ViewInteraction.java:153)
at android.support.test.espresso.ViewInteraction$1.call(ViewInteraction.java:150)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6501)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
有什么想法吗?
提前谢谢你。
【问题讨论】:
-
你能发一个stacktrace吗?
-
我可以,但没什么可展示的。它只抱怨动画时间(当然,我正在考虑)。
-
哦,这到底是怎么回事。堆栈跟踪已发布;)
-
实际上,您的匹配器工作正常,因为它表示有多个匹配项 - 原因:java.lang.RuntimeException:多个数据元素匹配:
标签: android layout android-espresso