UiAutomator sample: UiDevice.pressHome and startActivity timeouts
After code call UiDevice.pressHome(), it can not startActivity for 5 seconds (it gets delayed) unless activity was started from user interaction. So test startup is always slow. That's why you have 5 seconds LAUNCH_TIMEOUT :lollipop:
I did not found easy way to workaround it (there are hacky options). Please point out what can be done or at least document it's behavior.
Related code https://github.com/googlesamples/android-testing/blob/master/uiautomator/BasicSample/app/src/androidTest/java/com/example/android/testing/uiautomator/BasicSample/ChangeTextBehaviorTest.java#L62 Related readings https://code.google.com/p/android/issues/detail?id=4536 http://stackoverflow.com/questions/5600084/starting-an-activity-from-a-service-after-home-button-pressed-without-the-5-seco And I've made scaffolding test of stock dialer where I skip UiDevice.pressHome() https://github.com/logcat/uiautomator-template
Can you please file a bug for the support library under: https://code.google.com/p/android/issues/entry?template=Test%20Support%20Library%20bug
This is not a bug of support library. Go create bug for support library, and let support lib team close it. Amazing solution, I am not even mad :laughing:
You still have 5000 ms timeout. It's a joke to wait 5 seconds each time. You promote it as "the sample" in "google sample repo", brilliant :+1:
There is just no good way of synchronizing this. You can adjust the timeout to your needs in your test. The other thing that you could do is to use ActivityLifeCycleCallback's to track your target Activity in your test. But this sounds like something that could be solved at at the library level. That's why we suggested you to file a bug under the TESTING support library, so we can assign it the right person on the UIautomator team to see and look what they can improve there or offer other solutions.
If you use UiDevice.pressHome() and smaller timeouts, tests will fail. You can listen to ActivityLifeCycleCallback after you've pressed UiDevice.pressHome(), guess how long would it take? I bet for 5000ms.