testing-samples icon indicating copy to clipboard operation
testing-samples copied to clipboard

UiAutomator sample: UiDevice.pressHome and startActivity timeouts

Open logcat opened this issue 11 years ago • 4 comments

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

logcat avatar Jul 15 '15 17:07 logcat

Can you please file a bug for the support library under: https://code.google.com/p/android/issues/entry?template=Test%20Support%20Library%20bug

slinzner-corp avatar Dec 15 '15 14:12 slinzner-corp

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:

logcat avatar Dec 15 '15 18:12 logcat

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.

slinzner-corp avatar Dec 15 '15 20:12 slinzner-corp

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.

logcat avatar Dec 15 '15 20:12 logcat