insomniac
insomniac

Reputation: 379

Robotium ClickOnButton(int ID) method causes "junit.framework.AssertionFailedError: Button with index 2131034130 is not available!"

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!

Upvotes: 4

Views: 4600

Answers (2)

Renas
Renas

Reputation: 1919

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.

Upvotes: 13

insomniac
insomniac

Reputation: 379

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
        }
    }
}

Upvotes: 1

Related Questions