Android Automated Testing

How to get all Buttons on screen using Robotium

static void printAllButtons() {
ArrayList
print(“Total Buttons:” + allButtons.size());
for (Button vButton : allButtons) {
if (vButton.getVisibility() == View.VISIBLE) {
print(“Button ID: “
+ vButton.getId()
+ ” Tag:”
+ (vButton.getTag() != null ? vButton.getTag()
.toString() : “null”) + ” Value:”
+ vButton.getText().toString() + ” Visibility:”
+ vButton.getVisibility() + ” View String:”
+ vButton.toString());
}
}

}

How to get all TextViews on screen using Robotium

static void printAllTextViews() {
vTextViewsList = null;
vTextViewsList = solo.getCurrentViews(TextView.class);
print(“Total TextViews:” + vTextViewsList.size());
vIndex = 0;
for (TextView vTextView : vTextViewsList) {
if (vTextView.getVisibility() == View.VISIBLE) {
print(“TextView ID: “
+ vTextView.getId()
+ “Index: “
+ vIndex
+ ” Tag: “
+ (vTextView.getTag() != null ? vTextView.getTag()
.toString() : “null”) + ” Value: “
+ vTextView.getText().toString() + ” Visibility: “
+ vTextView.getVisibility() + ” View String: “
+ vTextView.toString());
vIndex++;
}
}

}

How to Get all Views on screen using Robotium

static void printAllViews() {
ArrayList allViews = solo.getCurrentViews();
print(“Total Views:” + allViews.size());
for (View vView : allViews) {
if (vView.getVisibility() == View.VISIBLE) {
print(“View : “ + vView.toString() + “View ID: “
+ vView.getId() + ” Value:”
+ vView.getClass().getName().toString()
+ ” Visibility:” + vView.getVisibility());
}
}

}

How to get All TextViews in each row of a ListView using Robotium

public void printAllTextViewsByRowIntoListView(){
vListView = solo.getCurrentViews(ListView.class).get(0);
        if (vListView.getCount() > 0) 
        {
          for (int i = 1; i <= vListView.getLastVisiblePosition(); i++) 
         
          vListRow = vListView.getChildAt(i);
          vTextViewsInListRow = solo.getCurrentViews(TextView.class, vListRow); 
          print(“Row #”+i+” contents “);
          for (int j = 0; j < vTextViewsInListRow.size(); j++) 
          { 
          print(vTextViewsInListRow.get(j).getText().toString());
          }
          print(“………”);
          }
        }
          else print(“No contents available”);
}