2010-08-26 42 views
2

我正在使用Instrumentation編寫自動化測試用例。 「waitforMonitorWithTimeout」 總是超時。如果我使用waitForMonitor,一切都很好。代碼的兩行 代碼如下。 (我在建立我的測試項目時註釋掉其中的一個)。Android waitForMonitorWithTimeout方法不起作用

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

活動currentActivity = instrumentation.waitForMonitor(monitor);

是否存在與「waitforMonitorWithTimeout」有關的已知問題?我必須使用超時 來確定是否發生事件(並因此轉換爲新活動)。

回答

3

我不知道waitforMonitorWithTimeout,但檢查活動已經啓動我在我的測試如下:

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)); 

我希望它能幫助,即使它不是答案你的問題。

+0

謝謝,但我已經使用「checkMonitorHit」添加了檢查,並且它也出現了錯誤。看起來好像當使用「waitforMonitorWithTimeout」時顯示器的實際設置/擊中功能不起作用。很幸運,我不能使用「waitforMonitor」(沒有超時),因爲導致監視器命中的動作可能會發生,也可能不會發生,我需要處理這兩種情況。 – Jack 2010-08-26 13:26:32

7

我發現我的問題 - 文檔指出延遲在。實際上延遲是在毫秒。 (至少在eclipse/Android領域就是這種情況)。當我使用30000而不是30--試圖延遲30秒 - 事情效果更好。

+0

有沒有人報告過這個問題? – Xample 2012-07-06 15:43:03

+0

從那時起已經有6年了,錯誤依然存在。 – Divers 2016-12-20 15:03:11