4

I am using robotium for testing and can't figure out how to click buttons without text. Test fails with trace:

junit.framework.AssertionFailedError: Button with index 2131034130 is not available!

cspolton
  • 4,495
  • 4
  • 26
  • 34
insomniac
  • 379
  • 5
  • 7

2 Answers2

13

The index system is there for black-box testing reasons So If you know the resource ID of the view you want to click you can use solo.getView(R.id) to get a hold of the object and then use solo.clickOnView(View view) to click it.

Aduait Pokhriyal
  • 1,529
  • 14
  • 30
Renas
  • 1,919
  • 1
  • 18
  • 17
1

I found that actual method parametr is not the ID, but "index",whenever it means. So my workaround is :

private void clickOnButtonByID(int ID) {
    // get a list of all ImageButtons on the current activity
    List<Button> btnList = solo.getCurrentButtons();
    for (int i = 0; i < btnList.size(); i++) {
        Button btn = btnList.get(i);
        // find button by id
        if (btn.getId() == ID) {
            // click on the button using index (not id !!!)
            solo.clickOnButton(i);
            // check if new activity is the 'About'
        } else {
            // other code
        }
    }
}
insomniac
  • 379
  • 5
  • 7