Android Espresso: PerformException

前端 未结 7 2013
春和景丽
春和景丽 2020-12-30 22:59

I`m getting

android.support.test.espresso.PerformException: Error performing \'send keyCode: 4, metaState: 0 key event\' on view \'Animations or tra

相关标签:
7条回答
  • 2020-12-30 23:26

    In my case, Espresso gave me the "Animations or transitions are not enabled..." error, but that wasn't actually the root cause.

    Scrolling through the stack trace I found this:

    androidx.test.espresso.PerformException: Error performing 'scroll to' on view 'Animations or transitions are enabled on the target device.
    
    ...
    
    Caused by: java.lang.RuntimeException:
      Action will not be performed because the target view does not match one or more
      of the following constraints:
        (view has effective visibility=VISIBLE and is descendant of a: (
          is assignable from class: class android.widget.ScrollView or
          is assignable from class: class android.widget.HorizontalScrollView or
          is assignable from class: class android.widget.ListView
        ))
    Target view: "LinearLayout{...}"
    

    That is, I was trying to scroll something that can't be scrolled.

    So, always read through the stacktrace folks

    0 讨论(0)
  • 2020-12-30 23:27

    I've run into the error Animations or transitions are enabled on the target device several times. In the latest case, the real problem was that my UI code was throwing a NullPointerException. Unfortunately Espresso was "swallowing" the NullPointerException and giving me the irrelevant error Animations or transitions are enabled on the target device.

    0 讨论(0)
  • 2020-12-30 23:27

    A simple try catch. Where you only pick up the exception if it is an PerformException.

    Alternativ add the 500 items to your shopping cart by code, and then add 1 extra by UI test.

    0 讨论(0)
  • 2020-12-30 23:34

    I had a similar error but after inspecting the logcat, I realised the fragment under test was trying to do a navigation and the nav graph wasn't defined in the test because the fragment had been launched with launchFragmentInContainer. Fixing that fixed the issue.

    0 讨论(0)
  • 2020-12-30 23:37

    In addition to the accepted answer, if you want to open the emulator from console, you have to add the following commands:

        - 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 &
    
    0 讨论(0)
  • 2020-12-30 23:38

    Animations or transitions are enabled on the target device.

    Espresso doesn't work well with animations due to the visual state delays they introduce. You need to disable animations on your device. Firstly, enable developer options:

    1. Open the Settings app.
    2. Scroll to the bottom and select About phone.
    3. Scroll to the bottom and tap Build number 7 times.
    4. Return to the previous screen to find Developer options near the bottom.

    Access Developer Options from Settings app, and under the Drawing section, switch all of the following options to Animation Off:

    • Window animation scale
    • Transition animation scale
    • Animator duration scale
    0 讨论(0)
提交回复
热议问题