Espresso test error: AppNotIdleException

前端 未结 4 1484
栀梦
栀梦 2020-12-11 14:32

I turned off all animations on developer options. But I still get this exception when trying to click on one of the buttons.

My app is indeed active and not idle ent

4条回答
  •  时光说笑
    2020-12-11 15:32

    In my case this problem was happening with AnimatedVectorDrawable and caused by an objectAnimator that was set to repeat the animation infinitely (android:repeatCount="infinite"). .

    The problem was also present only on older platform versions. Tests were perfectly working on Android 9 while the problem was reproducible on Android 5 and 6 (not sure about 7 and 8 at the moment).

    I believe, the root cause of the problem is the same as for indeterminate progress bars (covered in this SO question). However, I haven't found any nice solution, only workarounds.

    One of the workarounds is to detect that the animation is turned off (animator duration is 0) in the setting and don't start the animation. Of course, this only works for platform versions where the animation does not autostart.

    private fun startIconAnimation(imageView: ImageView) {
        if (areAnimationsEnabled()) {
            (imageView.drawable as Animatable).start()
        }
    }
    
    private fun areAnimationsEnabled(): Boolean {
        val animatorDurationScale = Settings.Global.getFloat(
            requireContext().contentResolver,
            Settings.Global.ANIMATOR_DURATION_SCALE,
            1.0f
        )
        return animatorDurationScale != 0.0f
    }
    

    Note: API level 26 introduced a static method ValueAnimator.areAnimatorsEnabled() which would have been handy if the problem was not happening only on the older platform versions.

提交回复
热议问题