0

我必须得到一个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!

请提出正确的方法。

4

2 回答 2

1

试试这个代码:

if(!solo.searchText("Current Location"))
    assertTrue(solo.searchText("my Text"))
else
    assertTrue(solo.searchText("Current Location"));
于 2014-02-18T09:31:05.717 回答
0
EditText view = (EditText) solo.getView(view1);

if(view == null){
    view = (EditText) solo.getView(view2)
}
view.getText().toString();
于 2014-02-18T07:09:15.960 回答