2014-02-18 18 views
0

我必須得到一個EditText對象,它不過是一個搜索欄,在應用與文本可見的Current Location,但是如果我已經做了一個搜索查詢與myText條件語句,沒有Current Location文字可見,並且搜索欄顯示myText用於獲取的TextView

我正在使用Robotium獨奏對象編寫測試用例。

我該如何寫條件語句來獲得EditText,儘管它顯示的是什麼文本。像

if !found solo.getText("Current Location") 
     search solo.getText("myText"); 

東西這是我在做什麼目前

EditText text = (EditText) solo.getText("Current Location"); 
if(text == null){ 
     text = (EditText) solo.getText("myText"); 
//my rest of the code goes here.... 

但是,這將引發異常,如果Current Location沒有出現在搜索欄中。

junit.framework.AssertionFailedError: TextView with text: 'Current Location' is not found! 

請建議正確的方法。

+0

什麼是'solo'對象? – Merlevede

+0

其Robotium。 android自動化工具。 –

回答

0
EditText view = (EditText) solo.getView(view1); 

if(view == null){ 
    view = (EditText) solo.getView(view2) 
} 
view.getText().toString(); 
1

嘗試使用此代碼:

if(!solo.searchText("Current Location")) 
    assertTrue(solo.searchText("my Text")) 
else 
    assertTrue(solo.searchText("Current Location"));