Slow down Espresso

跟風遠走 提交于 2019-12-08 15:58:57

问题


this is regarding Espresso. I am successfully running integration test on a simulator. I think some tests are failing because it's running too fast. Is there a way to slowdown the execution/playback speeD?


回答1:


It's impossible that a test fails cause to speed. Espresso can synchronize all test operations with the application under test. By default, Espresso waits for UI events in the current message queue to process and default AsyncTasks to complete before it moves on to the next test operation. However if this is not enough for your application you can tell Espresso when to be idle and when not. To do so you have to :

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

If you need more help ask me!!




回答2:


I had this problem too. I solved by removing activity animation on my device from Developer options.

If your problem is still there you can use sleep in your test to slow down.

SystemClock.sleep(1000);




回答3:


Haha...actually Espresso works like this only. The problem you are facing is that UI events are not able to complete (For example, clicking a list item before the list loads from a network call). In this case, where your resources are being loaded from other thread, you can actually perform Thread.sleep(millis) or more efficiently UiController's loopMainThreadForAtleast(millis) method to wait for something to load (event to complete).




回答4:


When you record an Espresso Test in Android Studio it will automatically add Sleep statements to tests when there is view interaction to handle the delay. This is the approach that is generated along with the comments:

// Added a sleep statement to match the app's execution delay.
// The recommended way to handle such scenarios is to use Espresso idling resources:
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html

try {
    Thread.sleep(700);
} catch (InterruptedException e) {
    e.printStackTrace();
}

Link to the docs



来源:https://stackoverflow.com/questions/36167938/slow-down-espresso

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!