Espresso 在云中的设备上运行时抛出“在视图中执行“单击”时出错”,但相同的测试在本地成功运行

Posted

技术标签:

【中文标题】Espresso 在云中的设备上运行时抛出“在视图中执行“单击”时出错”,但相同的测试在本地成功运行【英文标题】:Espresso throw " Error performing 'single click' on view” when it run on device in the cloud, but same test successfully run locally 【发布时间】:2017-10-12 17:35:18 【问题描述】:

我填写用户名和密码并按下通过网络发送信息的按钮(实现了 Espresso Idling 资源),在应用程序中出现下一个屏幕,我可以在日志中看到信息已发送。 但是测试失败并出现无法按下按钮的错误: android.support.test.espresso.PerformException:在视图上执行“单击”时出错,带有 id:

日志:

10-03 07:36:30.308:D/_IdlingResource(27742):_ 现在空闲!有:0 10-03 07:36:30.308: D/_IdlingResource(27742): _ 现在空闲!有:0 10-03 07:36:30.318: I/ViewInteraction(27742): 执行“替换” 带有 id 的视图上的文本操作:com._:id/user_name 10-03 07:36:30.358: D/_IdlingResource(27742): _ 现在空闲!与:0 10-03 07:36:30.358: D/_IdlingResource(27742): _ 现在空闲!与:0 10-03 07:36:30.358: I/ViewInteraction(27742):对视图执行“替换文本”操作 id:com._:id/password 10-03 07:36:30.388: D/_IdlingResource(27742): _ 现在空闲!与:0 10-03 07:36:30.388: D/_IdlingResource(27742): _ 现在空闲!有:0 10-03 07:36:30.388:I/ViewInteraction(27742):在 ID 为 com._:id/Button 的视图上执行“单击”操作 10-03 07:36:30.398: I/InputDispatcher(3416):向 (3959) 传递触摸:动作:0x4, 工具类型:0 10-03 07:36:30.398:I/InputDispatcher(3416):交付 触摸到(27742):动作:0x0,工具类型:0 10-03 07:36:30.398: D/ViewRootImpl(27742):ViewPostImeInputStage ACTION_DOWN 10-03 07:36:30.408: D/_IdlingResource(27742): _ 现在空闲!与:0 10-03 07:36:30.408: D/_IdlingResource(27742): _ 现在空闲!与:0 10-03 07:36:30.428: D/_IdlingResource(27742): _ 现在空闲!与:0 10-03 07:36:30.428: D/_IdlingResource(27742): _ 现在空闲!与:0 10-03 07:36:30.438: D/_IdlingResource(27742): _ 现在空闲!与:0 10-03 07:36:30.438: D/_IdlingResource(27742): _ 现在空闲!与:0 10-03 07:36:30.448: D/_IdlingResource(27742): _ 现在空闲!与:0 10-03 07:36:30.448: D/_IdlingResource(27742): _ 现在空闲!与:0 10-03 07:36:30.458: D/_IdlingResource(27742): _ 现在空闲!与:0 10-03 07:36:30.458: D/_IdlingResource(27742): _ 现在空闲!与:0 10-03 07:36:30.458: D/_IdlingResource(27742): _ 现在空闲!与:0 10-03 07:36:30.458: D/_IdlingResource(27742): _ 现在空闲!与:0 10-03 07:36:30.478: D/_IdlingResource(27742): _ 现在空闲!与:0 10-03 07:36:30.478: D/_IdlingResource(27742): _ 现在空闲!与:0 10-03 07:36:30.488:I/InputDispatcher(3416):向 (27742) 传递触摸: 动作:0x1,工具类型:0 10-03 07:36:30.498:D/Request(27742):方法: 1 个网址:https://。

****** 我删除了网络调用 **********

10-03 07:37:30.538: I/TestRunner(27742): android.support.test.espresso.PerformException:执行错误 '单击 - 在坐标:719、1367 和精度:16、16' on 查看 '带有 id: com.:id/Button'。 10-03 07:37:30.538: I/TestRunner(27742):在 android.support.test.espresso.PerformException$Builder.build(PerformException.java:83) 10-03 07:37:30.538:I/TestRunner(27742):在 android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:80) 10-03 07:37:30.538:I/TestRunner(27742):在 android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:56) 10-03 07:37:30.538:I/TestRunner(27742):在 android.support.test.espresso.ViewInteraction.runSynchronouslyOnUiThread(ViewInteraction.java:184) 10-03 07:37:30.538:I/TestRunner(27742):在 android.support.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:115) 10-03 07:37:30.538:I/TestRunner(27742):在 android.support.test.espresso.ViewInteraction.perform(ViewInteraction.java:87) 10-03 07:37:30.538:I/TestRunner(27742):在 页面._LinkAccountPage.clickOnLinkAccountButton(LinkAccountPage.java:62) 10-03 07:37:30.538:I/TestRunner(27742):在 页面._LinkAccountPage.linkAccount(LinkAccountPage.java:40) 10-03 07:37:30.538:I/TestRunner(27742):在 JunitTest.Test_BaseEspresso.searchAndLinkBill(Test_BaseEspresso.java:138) 10-03 07:37:30.538:I/TestRunner(27742):在 JunitTest_.Test_LinkFiCreditKycPayCurrentBalanceNewAchReceiptCancel.Test_LinkFiCreditKycPayCurrentBalanceNewAchReceiptCancel(Test_LinkFiCreditKycPayCurrentBalanceNewAchReceiptCancel.java:41) 10-03 07:37:30.538:I/TestRunner(27742):在 java.lang.reflect.Method.invoke(本机方法)10-03 07:37:30.538: I/TestRunner(27742):在 java.lang.reflect.Method.invoke(Method.java:372) 10-03 07:37:30.538: I/TestRunner(27742):在 org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) 10-03 07:37:30.538:I/TestRunner(27742):在 org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 10-03 07:37:30.538:I/TestRunner(27742):在 org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) 10-03 07:37:30.538:I/TestRunner(27742):在 org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) 10-03 07:37:30.538:I/TestRunner(27742):在 org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) 10-03 07:37:30.538:I/TestRunner(27742):在 org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) 10-03 07:37:30.538:I/TestRunner(27742):在 android.support.test.internal.statement.UiThreadStatement.evaluate(UiThreadStatement.java:55) 10-03 07:37:30.538:I/TestRunner(27742):在 android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:270) 10-03 07:37:30.538:I/TestRunner(27742):在 org.junit.rules.RunRules.evaluate(RunRules.java:20) 10-03 07:37:30.538:I/TestRunner(27742):在 org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) 10-03 07:37:30.538:I/TestRunner(27742):在 org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) 10-03 07:37:30.538:I/TestRunner(27742):在 org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) 10-03 07:37:30.538:I/TestRunner(27742):在 org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) 10-03 07:37:30.538:I/TestRunner(27742):在 org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) 10-03 07:37:30.538:I/TestRunner(27742):在 org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) 10-03 07:37:30.538:I/TestRunner(27742):在 org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) 10-03 07:37:30.538:I/TestRunner(27742):在 org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) 10-03 07:37:30.538:I/TestRunner(27742):在 org.junit.runners.ParentRunner.run(ParentRunner.java:363) 10-03 07:37:30.538:I/TestRunner(27742):在 org.junit.runners.Suite.runChild(Suite.java:128) 10-03 07:37:30.538: I/TestRunner(27742):在 org.junit.runners.Suite.runChild(Suite.java:27) 10-03 07:37:30.538: I/TestRunner(27742):在 org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) 10-03 07:37:30.538:I/TestRunner(27742):在 org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) 10-03 07:37:30.538:I/TestRunner(27742):在 org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) 10-03 07:37:30.538:I/TestRunner(27742):在 org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) 10-03 07:37:30.538:I/TestRunner(27742):在 org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) 10-03 07:37:30.538:I/TestRunner(27742):在 org.junit.runners.ParentRunner.run(ParentRunner.java:363) 10-03 07:37:30.538:I/TestRunner(27742):在 org.junit.runner.JUnitCore.run(JUnitCore.java:137) 10-03 07:37:30.538: I/TestRunner(27742):在 org.junit.runner.JUnitCore.run(JUnitCore.java:115) 10-03 07:37:30.538: I/TestRunner(27742):在 android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59) 10-03 07:37:30.538:I/TestRunner(27742):在 android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:262) 10-03 07:37:30.538:I/TestRunner(27742):在 android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1889) ************** 请注意以下错误** 10-03 07:37:30.538: I/TestRunner(27742): 原因: android.support.test.espresso.AppNotIdleException:在 60 秒内循环了 3585 次迭代。以下空闲条件失败。 10-03 07:37:30.538:I/TestRunner(27742):在 android.support.test.espresso.IdlingPolicy.handleTimeout(IdlingPolicy.java:61) 10-03 07:37:30.538:I/TestRunner(27742):在 android.support.test.espresso.base.UiControllerImpl.loopUntil(UiControllerImpl.java:480) 10-03 07:37:30.538:I/TestRunner(27742):在 android.support.test.espresso.base.UiControllerImpl.loopUntil(UiControllerImpl.java:411) 10-03 07:37:30.538:I/TestRunner(27742):在 android.support.test.espresso.base.UiControllerImpl.injectMo 10-03 07:37:30.538: I/TestRunner(27742): ----- 结束异常 ----- 10-03 07:37:30.538:I/TestRunner(27742):完成: Test_LinkFiCreditKycPayCurrentBalanceNewAchReceiptCancel(JunitTest_.Test_LinkFiCreditKycPayCurrentBalanceNewAchReceiptCancel) 10-03 07:37:30.578:I/MonitoringInstrumentation(27742):活动 仍在创建到停止:3 10-03 07:37:30.578: I/MonitoringInstrumentation(27742):完成活动: com..core.provider.AddProviderActivity@3f31fd61 10-03 07:37:30.578: V/ApplicationPolicy(3416): isApplicationStateBlocked userId 0 pkgname com. 10-03 07:37:30.578: V/ApplicationPolicy(3416): isApplicationStateBlocked userId 0 pkgname com._ 10-03 07:37:30.578: D/InputDispatcher(3416):重点应用程序设置为:xxxx 10-03 07:37:30.588: I/ActivityManager(3416): 跳过更新缩略图 r=ActivityRecord23d1bfe2 u0 com./.core.provider.AddProviderActivity t5 f 10-03 07:37:30.588:I/MonitoringInstrumentation(27742): 收尾活动: com..core.overview.NewUserSignUpIntroScreen@18c65aea 10-03 07:37:30.598:I/MonitoringInstrumentation(27742):完成活动: com..core.provider.SearchProviderActivity@33d373f6 10-03 07:37:30.598: V/ApplicationPolicy(3416): isApplicationStateBlocked userId 0 pkgname com. 10-03 07:37:30.598: V/ApplicationPolicy(3416): isApplicationStateBlocked userId 0 pkgname com.google.android.apps.mtaas.backdrop 10-03 07:37:30.598: D/InputDispatcher(3416):重点应用程序设置为:xxxx 10-03 07:37:30.598:D/MultiWindowConverter(3416):dismissGuide():之前 附加指南视图,mForceDismissGuide:false 10-03 07:37:30.598:D/InputDispatcher(3416):焦点左窗口:27742 10-03 07:37:30.598:I/TestRunner(27742):运行完成:1 个测试,1 个失败,0 忽略 10-03 07:37:30.608: I/System.out(27742): (HTTPLog)-Static: isSBSettingEnabled 假 10-03 07:37:30.608: D/PointerIcon(3416): setMouseIconStyle1 指针类型:1001 图标类型:101 标志:0 PID:3416 uid:1000 10-03 07:37:30.608: D/PointerIcon(3416): setMouseCustomIcon IconType 相同。101 10-03 07:37:30.608: D/EnterpriseController(2962): mIsMarkChainAdded 为 0 mIsBlockChainAdded 为 0 netId 为 0 10-03 07:37:30.608: D/Netd(2962): getNetworkForDns: 使用 netid 502 作为 uid 10207 10-03 07:37:30.608:D/生命周期(27742):onActivityPaused: core.provider.AddProviderActivity

【问题讨论】:

您有没有找到造成这种情况的原因? 我也有同样的问题,点击视图后测试失败,应用程序进入下一个屏幕。 【参考方案1】:

当您在其字段隐藏在软键盘后面的屏幕上工作时,通常会出现这种错误。因此,您应该做几件事:

    使布局可滚动并使用 ViewActions.scrollTo 执行滚动到该字段。 使用 ViewActions.closeSoftKeyboard 关闭 que 软键盘

一个例子:

String OLD_PWD_INPUT = "Asdf1234;";
onView(withId(R.id.old_password)).perform(typeText(OLD_PWD_INPUT));
onView(withId(R.id.verify_new_password)).perform(closeSoftKeyboard());
onView(withId(R.id.change_password_button)).check(matches(not(isEnabled())));

String NEW_PWD_INPUT = "Asdf1235;";
onView(withId(R.id.new_password)).perform(scrollTo());
onView(withId(R.id.new_password)).perform(typeText(NEW_PWD_INPUT));
onView(withId(R.id.verify_new_password)).perform(closeSoftKeyboard());
onView(withId(R.id.change_password_button)).check(matches(isEnabled()));

【讨论】:

以上是关于Espresso 在云中的设备上运行时抛出“在视图中执行“单击”时出错”,但相同的测试在本地成功运行的主要内容,如果未能解决你的问题,请参考以下文章

Appium Pagefactory 从 POM 运行时抛出 noSuchMethodException

ScriptManager.GetCurrent ( Page ).IsInAsyncPostBack 在运行时抛出错误

Ruby脚本在cron运行时抛出错误,但在用户运行时不会

PouchDB 复制在复制时抛出错误

AccountManagerFuture.getResults 在连接处于活动状态时抛出 IOException

Selenium 在旋转代理时抛出 InvalidArgumentException