Espresso testing disable animation

enter image description here

@Test
    public void test3_PaySuccessful(){
        init();

    ViewInteraction amountEditText = onView(
            allOf(withId(R.id.et_amount), isDisplayed()));
    amountEditText.perform(replaceText("SGD 0.010"), closeSoftKeyboard());

    //, withText("Proceed")
    ViewInteraction appCompatButton = onView(
            allOf(withId(R.id.btn_confirm), isDisplayed()));
    appCompatButton.perform(click());

    //, withText("Pay")
    ViewInteraction appCompatButton2 = onView(
            allOf(withId(R.id.btn_confirm), isDisplayed()));
    appCompatButton2.perform(click());

    //dialog
    ViewInteraction appCompatButton3 = onView(
            allOf(withId(R.id.confirm_button), withText("Confirm"), isDisplayed()));
    appCompatButton3.perform(click());

    //have to disable animation in order to pass this.
    intended(CoreMatchers.allOf(hasComponent(PaymentSelectionActivity2.class.getName())));

}

I ran into a problem when testing Espresso with a view that included animation, I know that Espresso cannot deal with animation, so I did this below. - disable my test device. Window animation, transition animation, and animator animation duration are all set to OFF (this does not work) - then I tried to add a flag to my code, for example. espresso_testing = true. if true, my code skips the call to the startAnimation () function. ---> It works. However, there is a requirement that I cannot change the code in my application while writing an espresso test. The test case above is included.

Is there any other way to do this? Thanks in advance.

+6
3

, :

buildscript {
  repositories {
    maven { url "https://plugins.gradle.org/m2/" }
  }

  dependencies {
    classpath "com.android.tools.build:gradle:2.3.1"
  }
}

testOptions, animationsDisabled:

android {

  ...

  testOptions {
    animationsDisabled = true
  }
}

: https://google.imtqy.com/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.TestOptions.html#com.android.build.gradle.internal.dsl.TestOptions:animationsDisabled

- :

# Turn off animations
adb shell settings put global window_animation_scale 0 &
adb shell settings put global transition_animation_scale 0 &
adb shell settings put global animator_duration_scale 0 &

: https://github.com/jaredsburrows/android-gif-example/blob/master/.travis.yml#L34

+15

repo

.apk , , , . .apk . , .apk, :

 adb install -r android_emulator_hacks.apk
 adb shell pm grant no.finn.android_emulator_hacks android.permission.SET_ANIMATION_SCALE
 adb shell am start -n no.finn.android_emulator_hacks/no.finn.android_emulator_hacks.HackActivity

.

+1

, . . Handlers Runnables, . , , - .

ValueAnimator, ObjectAnimator AnimatorSet . , Animator duration scale .

A good reference is ProgressBar.

0
source

Source: https://habr.com/ru/post/1016947/


All Articles