2012-05-23 38 views
1

我有一個txt.setError文本,我想檢查是錯誤出現在屏幕上,而在testin我的測試用例是;Robotium搜索edittext的setError

solo.enterText(0, "example"); 
solo.clickOnImageButton(3); 
assertTrue(solo.searchText("E-posta adresleri için lütfen şu biçimi kullanın: [email protected]")); 

enter image description here

我得到了SETERROR文字的onclick的ImageButton的

之後,但我得到了AssertionFailedError異常 我在做什麼錯?

編輯:

問題的來源是Robotium的RELASE。我使用2.1,但是對於這個斷言,robotium 3.0和upper是必要的。

+0

彈出時,它在1行書面方式或你有一個/ n做一個新的行? 您可以嘗試搜索部分文本。像:E-posta adresleriiçin –

+0

不,我沒有得到一個新的線。它只是一個句子 – Merve

+0

我嘗試了assertTrue(solo.searchText(「E-posta adresleriiçin」));但它給出了同樣的錯誤。也許這是因爲setError發生的? – Merve

回答

2

嘗試使用solo.waitfortext()而不是assertTrue(solo.searchText())。 問題可能是在顯示文本之前斷言正在執行。

所以我會說你有兩種可能的選擇。

選項1:

solo.enterText(0, "example"); 
solo.clickOnImageButton(3); 
solo.waitforactivity(solo.getcurrentactivity().tostring). // you will wait untill the screen is entirely displayed. 
assertTrue(solo.searchText("E-posta adresleri için lütfen şu biçimi kullanın: [email protected]")); 

選項2(最好的選擇)

solo.enterText(0, "example"); 
solo.clickOnImageButton(3); 
boolean textExist = solo.WaitForText("E-posta adresleri için lütfen şu biçimi kullanın: [email protected]")); 
if (!textExist){ 
Fail(); 
} 
0

另一種選擇:

EditText myEditText = (android.widget.EditText) solo.getView(com.my.app.R.id.myEditText); 
solo.clickOnView(myButton); 

//Waits for error 
solo.sleep(2000); 

boolean result = myEditText.getError() == null; 
if(!result){ 
    fail(); 
}