Reputation: 8364
I am asserting some views which will be displayed after some animation or loads slowly
Ex:- Search button on the action bar is delayed to display on the action bar, before its displayed assertion fails, it should wait?
And in lollipop we have a ripple blow animation and after that some views are displayed but assertion fails before animation is finished, espresso should wait for all views and animation to become idle right? When I used custom idling resource and waiting for 2 sec's that time it worked, but thats not the right way.
//Its my custom idling resource which wait for 2000 millisec
EspressoSolo.sleep(200);
RecordingTest.getDefault().customTests(1, 1);
Upvotes: 2
Views: 6804
Reputation: 5081
I'm copying in what the Google tutorial instructs us to do:
On your device, under Settings->Developer options disable the following 3 settings:
Window animation scale
Transition animation scale
Animator duration scale
This turns off the animations and allows your tests to run.
Upvotes: 0
Reputation: 1847
Most of the resources that I've found (like the one above) links to a dead page.
I found this blog post but it also links to the dead link above as well, but it proved useful because it provides step by step instructions on how to set it up.
http://product.reverb.com/2015/06/06/disabling-animations-in-espresso-for-android-testing/
I've been having a similar issues because I have animations that I need to wait for before I can click buttons and such. I later learned that Espresso recommends disabling animations during testing, as what Alexandre pointed out.
You can read how to add it to your run configurations at the bottom of the blog post.
To get the task to run before the tests: In the dropdown that shows what to run (“app” or “Android Tests” or “Unit Test”), select “Edit Configurations” then the main “Android Tests” Configuration. Near the bottom is a box labeled “Before launch:”. Hit the “+” to expand the “Add New Configuration” dialog box and select “Run Gradle task”. For Gradle Project select your app, then for “Tasks” enter grantAnimationPermission, which should auto-complete.
Alternatively, you can go to 'Developer Settings' on your mobile or virtual device and set your animation scales to off.
Note however, I found out that this does not disable my in-line animations like the following:
new Handler().postDelayed(new Runnable() {
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
@Override
public void run() {
try {
layout_login.animate()
.translationY(0)
.alpha(1)
.setDuration(500)
.setInterpolator(new AccelerateDecelerateInterpolator());
} catch (Exception e) {
}
}
}, 1600);
Upvotes: 2