Reputation: 9791
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.
Upvotes: 0
Views: 622
Reputation: 706
Try with this code:
if(!solo.searchText("Current Location"))
assertTrue(solo.searchText("my Text"))
else
assertTrue(solo.searchText("Current Location"));
Upvotes: 1
Reputation: 5819
EditText view = (EditText) solo.getView(view1);
if(view == null){
view = (EditText) solo.getView(view2)
}
view.getText().toString();
Upvotes: 0