2013-05-17 26 views
3

我正在使用robotium。今天我碰到了一點小問題。點擊按鈕後,應用程序將轉到下一個活動。我需要等待出現一些按鈕。Robotium solo waitForCondition

View am = solo.getView(R.id.btn_login); 

solo.waitForCondition(am.isShown(), 5000); 

此代碼無效。

它還如果不起作用標識像

Button am = solo.getButton(R.id.btn_login); 

請幫助我看着辦吧!

+0

你可以請給我們你的班級 請?謝謝 – Jarvis

回答

0

Android中的isShown()經常被誤解。當視圖及其所有祖先都可見時,它將返回true。

我覺得你可以只是嘗試:

solo.waitForView(...) 
+0

好吧,我會試試這個。謝謝 – ELEGANCE

0

在Robotium,有不同的waitForCondition。如:

solo.waitForView() //if a certain view is shown after the load screen is done. 
solo.waitForDialogToClose() //waits for the dialog to close 
solo.waitForActivity() // if there is a activity change 
solo.waitForText() //if a certain text appears after the loading is done 

在你的情況,因爲你知道等待項目的ID,你可以嘗試:

solo.waitForView(R.id.btn_login, 5000); 
6

您對實現Condition接口:

solo.waitForCondition(new Condition() { 
    @Override 
    public boolean isSatisfied() { 
     return am.isShown(); 
    } 
}, 5000); 

isSatisfied()你可以自由地測試你需要的任何東西:)