0

I have to get a EditText object which is nothing but a search bar in app with text visible as Current Location, however if I've already made a search query with myText, there is no Current Location text visible and search bar shows myText.

I am writing the test cases using Robotium solo object.

How can i write a conditional statement to get the EditText despite of what text it shows. Something like

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

This is what I am doing currently

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

But this throws exception if Current Location is not present in the search bar.

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

Please suggest the correct way.

roger_that
  • 9,493
  • 18
  • 66
  • 102

2 Answers2

1

Try with this code:

if(!solo.searchText("Current Location"))
    assertTrue(solo.searchText("my Text"))
else
    assertTrue(solo.searchText("Current Location"));
Flavio Capaccio
  • 706
  • 4
  • 15
0
EditText view = (EditText) solo.getView(view1);

if(view == null){
    view = (EditText) solo.getView(view2)
}
view.getText().toString();
Paul Harris
  • 5,769
  • 1
  • 25
  • 41