tags:

views:

12

answers:

2

I am writing automated test cases using Instrumentation. "waitforMonitorWithTimeout" always timesout. If I use waitForMonitor everything is fine. The two lines of code are below. (I comment out one of them when building my test project).

Activity currentActivity = instrumentation.waitForMonitorWithTimeout(monitor, (long)30);

Activity currentActivity = instrumentation.waitForMonitor(monitor);

Are there known issues with "waitforMonitorWithTimeout"? I have to use the timeout to determine if an event occured (and thus transition to a new activity) or not.

A: 

I don't know about waitforMonitorWithTimeout, but to check if an activity has been launched I do the following in my tests:

ActivityMonitor monitor = getInstrumentation().addMonitor(
                  SomeActivity.class.getCanonicalName(), null, true);
//Do something, for example press a focused button
sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
//check the activity has been launched 1 time
assertTrue(getInstrumentation().checkMonitorHit(monitor, 1));

I hope it helps, even if it's not the answer to your question.

Maragues
Thanks but I've added checks using "checkMonitorHit" and its coming up false as well. It seems as if the actual setting/hitting of the monitor isn't functioning when using "waitforMonitorWithTimeout". Unfrotunately I can't use "waitforMonitor" (without the timeout) since the action causing the monitor to hit may or may not occur and I need to handle both scenarios.
Jack
A: 

I found my problem - the documentation states that the delay is in seconds. In fact the delay is in milliseconds. (At least this is the case in the eclipse/Android realm). When I used 30000 instead of 30 - trying to get a 30 second delay - things worked much better.

Jack