How to disable animations in code when running Espresso tests

后端 未结 3 1853
眼角桃花
眼角桃花 2020-12-29 08:54

Has anybody managed to disable animations through code when running Espresso tests? I\'ve been trying to follow the instructions in this webpage (linked to from he

相关标签:
3条回答
  • 2020-12-29 09:28

    I finally got this to work. Here is a Gist listing the required steps:
    https://gist.github.com/daj/7b48f1b8a92abf960e7b

    The key step that I had missed was running adb to grant the permission:

    adb shell pm grant com.mypackage android.permission.SET_ANIMATION_SCALE    
    

    Adding the permission to the manifest and running the reflection steps did not seem to be enough on their own.

    0 讨论(0)
  • 2020-12-29 09:45

    Even better approach is to update app/build.gradle, if you're running tests from command line.

    android {
        ...
        ...
    
        testOptions {
            animationsDisabled = true
        }
    }
    

    You may have to do ./gradlew clean before rebuilding. If you used android studio, it may not update the apk on your device assuming that nothing changed in the apk. Watch out for those to ensure that the change is actually taking effect on your device.

    Also read the documentation here.

    Disables animations during instrumented tests you run from the cammand line.

    If you set this property to true, running instrumented tests with Gradle from the command line executes am instrument with the --no-window-animation flag. By default, this property is set to false.

    This property does not affect tests that you run using Android Studio.

    0 讨论(0)
  • 2020-12-29 09:46

    I'm executing these three commands for each animation type and they are working for me:

    adb shell settings put global window_animation_scale 0.0
    adb shell settings put global transition_animation_scale 0.0
    adb shell settings put global animator_duration_scale 0.0
    

    More information here - prepare android emulator for UI test automation.

    0 讨论(0)
提交回复
热议问题