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 tes开发者_开发百科t 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.
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.
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.
精彩评论