I`m getting
android.support.test.espresso.PerformException: Error performing \'send keyCode: 4, metaState: 0 key event\' on view \'Animations or tra
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
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
.
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.
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.
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 &
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:
Access Developer Options from Settings app, and under the Drawing section, switch all of the following options to Animation Off: