Last active
May 21, 2020 17:21
-
-
Save balachandarlinks/91c4ff8a907824d75f3feadccd774c87 to your computer and use it in GitHub Desktop.
Disable animations for Android UI tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Don't forget to change test runner in app's build.gradle file | |
... | |
android { | |
... | |
defaultConfig { | |
... | |
testInstrumentationRunner "in.bala.TestRunner" | |
} | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.app.Application | |
import android.content.Context | |
import android.os.Bundle | |
import android.provider.Settings.Global.* | |
import androidx.test.platform.app.InstrumentationRegistry | |
import androidx.test.runner.AndroidJUnitRunner | |
class TestRunner : AndroidJUnitRunner() { | |
override fun onCreate(arguments: Bundle?) { | |
super.onCreate(arguments) | |
setAnimations(false) | |
} | |
override fun finish(resultCode: Int, results: Bundle?) { | |
setAnimations(true) | |
super.finish(resultCode, results) | |
} | |
private fun setAnimations(enabled: Boolean) { | |
val value = if (enabled) "1.0" else "0.0" | |
InstrumentationRegistry.getInstrumentation().uiAutomation.run { | |
this.executeShellCommand("settings put global $WINDOW_ANIMATION_SCALE $value") | |
this.executeShellCommand("settings put global $TRANSITION_ANIMATION_SCALE $value") | |
this.executeShellCommand("settings put global $ANIMATOR_DURATION_SCALE $value") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment