Reputation: 2710
I'm trying to test my application through ActivityInstrumentationTestCase2. I have a few clickables in my UI. I use sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
etc to simulate keyevents on my UI.
The problem is is my app is kinda slow whereas the test case is relatively fast. So what's happening is that the keyevents sometimes click/navigate to the wrong UI element and that messes up the test case.
Is there any other way of simulating keyevents with a tiny bit of delay ? For now i'm using
Thread.sleep(500)
to introduce a minor delay.
Is there a more elegant way of doing it other than using Thread.sleep()
?
Note: I am aware of Robotium and I'd appreciate it if the answers were related to the Android Test Framework. Thanks.
Upvotes: 0
Views: 323
Reputation: 3720
There is sleep method in robotium, so you can replace all your Thread.sleep with:
solo.sleep(long ms);
There is also another way, which UIAutomator uses, however I'm not sure, if it's safe and will not cause freezing of UI:
SystemClock.sleep(long ms);
You can also use wait methods, if you are sure that some view is going to appear. Take a look on robotium api, you will see what else can be useful for you.
Upvotes: 1