无法使用Espresso单击元素。代码是
onView(withId(R.id.nav_btn_menu)).perform(click());
我想单击上面的ImageButton,但是它抛出错误为
android.support.test.espresso.PerformException: Error performing 'single click - At Coordinates: 727, 1207 and precision: 16, 16' on view 'with id: com.xyz.p2p.app:id/nav_btn_menu'.
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 com.xyz.p2p.app.Test8_OrgRegisterNumberActivityTest.test1_onCreate_Serviceno(Test8_OrgRegisterNumberActivityTest.java:214)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
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.runner.junit4.statement.RunBefores.evaluate(RunBefores.java:80)
at android.support.test.internal.runner.junit4.statement.RunAfters.evaluate(RunAfters.java:61)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:527)
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:1867)
Caused by: android.support.test.espresso.PerformException: Error performing 'click (after 3 attempts)' on view 'unknown'.
at android.support.test.espresso.PerformException$Builder.build(PerformException.java:82)
at android.support.test.espresso.action.MotionEvents.sendDown(MotionEvents.java:119)
at android.support.test.espresso.action.Tap.sendSingleTap(Tap.java:168)
at android.support.test.espresso.action.Tap.access$100(Tap.java:31)
at android.support.test.espresso.action.Tap$1.sendTap(Tap.java:47)
at android.support.test.espresso.action.GeneralClickAction.perform(GeneralClickAction.java:136)
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:237)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5653)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Test running failed: Instrumentation run failed due to 'Process crashed.'
注意:可以单击同一页面上同一行中的其他按钮。实际上,有两个按钮的可见性切换。同一位置的其他按钮的元素也显示相同的错误。
有人可以告诉我我在做什么错吗?
答案 0 :(得分:0)
我有一个类似的问题,它是ImageView而不是ImageButton。我就像您能够测试类似视图的点击,而不仅仅是一个按钮。唯一的区别是,在imageView中,我正在旋转图像,但是当我移除旋转后,它才起作用
<ImageView
android:id="@+id/image"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginEnd="8dp"
android:rotation="180"
android:src="@drawable/back"
app:layout_constraintBottom_toBottomOf="@+id/top_view"
app:layout_constraintEnd_toEndOf="@+id/top_view"
app:layout_constraintTop_toTopOf="parent" />
这是引起问题的原因: android:rotation =“ 180”