Slow espresso

This applies to espresso. I successfully complete an integration test on a simulator. I think some tests fail because they work too fast. Is there a way to slow speeD execution / playback?

+6
source share
4 answers

It is impossible that the test does not help speed up. Espresso can synchronize all test operations with the application under test. By default, Espresso waits for user interface events in the current message queue to process and, by default, AsyncTasks to complete before proceeding to the next test operation. However, if this is not enough for your application, you can tell the espresso when it is idle and when not. For this you need:

  • Add the IdlingResource interface.
  • Register one or more of your IdlingResource (s) with Espresso by calling Espresso.registerIdlingResource in the test setup.

If you need more help, ask me.

+4
source

Haha ... in fact, espresso works just that. The problem you are facing is that user interface events cannot be completed (for example, clicking a list item before loading a list from a network call). In this case, when your resources are loaded from another thread, you can actually execute Thread.sleep (millis) or more efficiently UiController loopMainThreadForAtleast (millis) to wait for something to load (event to complete).

0
source

When you record an espresso test in Android Studio, it automatically adds Sleep statements to the tests when there is interaction with the view to handle the delay. This is the approach that is generated along with the comments:

 // Added a sleep statement to match the app execution delay. // The recommended way to handle such scenarios is to use Espresso idling resources: // https://google.imtqy.com/android-testing-support-library/docs/espresso/idling-resource/index.html try { Thread.sleep(700); } catch (InterruptedException e) { e.printStackTrace(); } 

Link to documents

0
source

I also had this problem. I decided to remove the activity animation on my device from the developer options.

If your problem still exists, you can use sleep in your test to slow down.

 SystemClock.sleep(1000); 

enter image description here

-one
source

All Articles