Espresso测试在模拟器上失败(在视图上执行操作时出错)

时间:2017-09-06 22:58:32

标签: android android-testing android-espresso

这是我第一次使用Espresso。在我的设备上工作时工作流程非常棒,但是当使用模拟器时(也在CI上),每次基于espresso的测试都会失败并出现相同的错误。

错误是Error performing <action> on <view>,例如:

android.support.test.espresso.PerformException: Error performing 'fast swipe' on view 'is <com.package.ScrollGestureLayout{16806b3 V.E..... ........ 0,0-1000,1000}>'.
at android.support.test.espresso.PerformException$Builder.build(PerformException.java:84)
at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:81)
at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:52)
at android.support.test.espresso.ViewInteraction.waitForAndHandleInteractionResults(ViewInteraction.java:312)
at android.support.test.espresso.ViewInteraction.desugaredPerform(ViewInteraction.java:167)
at android.support.test.espresso.ViewInteraction.perform(ViewInteraction.java:110)
at com.package.ScrollGestureLayoutTest.testScroll(ScrollGestureLayoutTest.java:57)
at com.package.ScrollGestureLayoutTest.testScrollUp(ScrollGestureLayoutTest.java:85)
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.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:433)
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 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:58)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:375)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1853)


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:84)
at android.support.test.espresso.action.MotionEvents.sendDown(MotionEvents.java:115)
at android.support.test.espresso.action.MotionEvents.sendDown(MotionEvents.java:48)
at android.support.test.espresso.action.Swipe.sendLinearSwipe(Swipe.java:87)
at android.support.test.espresso.action.Swipe.access$100(Swipe.java:30)
at android.support.test.espresso.action.Swipe$1.sendSwipe(Swipe.java:37)
at android.support.test.espresso.action.GeneralSwipeAction.perform(GeneralSwipeAction.java:68)
at android.support.test.espresso.ViewInteraction$SingleExecutionViewAction.perform(ViewInteraction.java:356)
at android.support.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:241)
at android.support.test.espresso.ViewInteraction.access$100(ViewInteraction.java:62)
at android.support.test.espresso.ViewInteraction$1.call(ViewInteraction.java:149)
at android.support.test.espresso.ViewInteraction$1.call(ViewInteraction.java:146)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)

基本上它导致了MotionEvents.sendDown() click()。所有这些只需在视图上执行操作即可。所有行动都不会发生这种情况:

  • GeneralClickAction:正常工作
  • swipeUp():崩溃
  • swipeDown()longClick(),...:崩溃
  • doubleClick()@Rule public ActivityTestRule<TestActivity> rule = new ActivityTestRule<>(TestActivity.class); private ScrollGestureLayout mView; @Before public void setUp() { // Create mView and add it to the activity (UI thread) } @Test public void testNothing() { onView(is(mView)).perform(longClick()); // Or, for example: onView(is(mView)).perform(longClick()).check(matches(anything())); } ...:崩溃

有谁知道发生了什么?

testNothing()

此{{1}}始终在我的设备上运行,而在模拟器上始终失败。我知道视图是匹配的,我已经尝试过自定义匹配器进行检查。它只是没有执行该操作。

设备:API 26.仿真器:API 22. Espresso:3.0.1。

0 个答案:

没有答案