2

I already did these steps

To avoid flakiness, we highly recommend that you turn off system animations on the virtual or physical device(s) used for testing.

On your device, under Settings->Developer options disable the following 3 settings:
Window animation scale
Transition animation scale
Animator duration scale

But somewhere in my code I use this

animation = new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
animation.setInterpolator(new LinearInterpolator());
animation.setRepeatCount(Animation.INFINITE);
animation.setDuration(5000);
imageScanLogo.startAnimation(animation);

In my Espresso Test class I perform a click on that view with

onView(withId(R.id.imageScanLogo)).perform(click());

After that it gets stuck at that point and does not advance anymore. When I comment the animation out of the code, it works just fine. This is the stacktrace, it says he could not click on the view but in fact he clicked on it and did not progress any further in the test.

android.support.test.espresso.PerformException: Error performing 'single click - At Coordinates: 539, 946 and precision: 16, 16' on view 'with id: com.android.x.y/imageScanLogo'.
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.android.x.y.BaseTests.scanTagsAndUpload(BaseTests.java:88)
at com.android.x.y.CleanScanTest.scan(CleanScanTest.java:61)
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 org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
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 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:59)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:262)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1879)
Caused by: android.support.test.espresso.AppNotIdleException: Looped for 4864 iterations over 30 SECONDS. The following Idle Conditions failed .
at android.support.test.espresso.IdlingPolicy.handleTimeout(IdlingPolicy.java:61)
at android.support.test.espresso.base.UiControllerImpl.loopUntil(UiControllerImpl.java:480)
at android.support.test.espresso.base.UiControllerImpl.loopUntil(UiControllerImpl.java:411)
at android.support.test.espresso.base.UiControllerImpl.injectMotionEvent(UiControllerImpl.java:229)
at android.support.test.espresso.action.MotionEvents.sendUp(MotionEvents.java:138)
at android.support.test.espresso.action.MotionEvents.sendUp(MotionEvents.java:118)
at android.support.test.espresso.action.Tap.sendSingleTap(Tap.java:135)
at android.support.test.espresso.action.Tap.access$100(Tap.java:35)
at android.support.test.espresso.action.Tap$1.sendTap(Tap.java:40)
at android.support.test.espresso.action.GeneralClickAction.perform(GeneralClickAction.java:98)
at android.support.test.espresso.ViewInteraction$1.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:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

My timeout policy is set like this

@Before
    public void resetTimeout() {
        IdlingPolicies.setMasterPolicyTimeout(30, TimeUnit.SECONDS);
        IdlingPolicies.setIdlingResourceTimeout(20, TimeUnit.SECONDS);
    }

I do not want to comment every single animation out of the code and also not start building some flags to whether enable/disable animations for the test.

Community
  • 1
  • 1
Murat Karagöz
  • 35,401
  • 16
  • 78
  • 107

2 Answers2

2

Try using the Animator API instead as it's the preferred animation method since Honeycomb (3.0).

ObjectAnimator anim = ObjectAnimator.ofInt(imageScanLogo, "rotation", 0, 360);
anim.setRepeatCount(ValueAnimator.INFINITE);
animation.setInterpolator(new LinearInterpolator());
animation.setDuration(5000);
anim.start();

Perhaps Espresso doesn't check for the old Animation API or disabling animations in the developers setting doesn't apply to the old animations.

Tim Kist
  • 1,164
  • 1
  • 14
  • 38
1

Espresso just performs validation on Views when application is Idle (All AsyncTask finished). By default it waits for 60s then throws AppNotIdleException, You changed this to 30s, during this time your app is not idle yet, So change it to higher value may help.

Toan Tran Van
  • 695
  • 1
  • 7
  • 25
  • Does not change anything. It works when I comment out the animation. – Murat Karagöz Aug 18 '16 at 10:33
  • Yes, I think The animation may take up to 30s to finish therefore your app is not Idled. Please change 30s to higher Ex:60s, 90s and check again – Toan Tran Van Aug 18 '16 at 10:35
  • If that animation is infinite then I don't have any idea :D. Please check more if you are using AsynsTask to handle this animation, change it to a kind of Thread (that is not managed by our main thread) is other solution – Toan Tran Van Aug 18 '16 at 10:45
  • I changed the repeat count to zero to test it and it works as you said. But I need a solution to work with infinite animations – Murat Karagöz Aug 18 '16 at 10:50
  • Use it with Thread. If you use AsyscTask, Espresso will wait until AsyscTask is finished. Therefore, If AsysnTask is running forever, Espresso can't run – Toan Tran Van Aug 18 '16 at 10:51