我必须得到一个EditText
对象,它只是应用程序中的一个搜索栏,文本可见Current Location
,但是如果我已经使用 进行了搜索查询myText
,则没有Current Location
可见的文本并且搜索栏显示myText
。
我正在使用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!
请提出正确的方法。