The Robotium ClickOnButton (int ID) method calls "junit.framework.AssertionFailedError: button with index 2131034130 is unavailable!"

I use robotium for testing and cannot figure out how to press buttons without text. Testing fails with the error:

junit.framework.AssertionFailedError: button with index 2131034130 is unavailable!

+4
source share
2 answers

An index system exists for black box testing purposes. Therefore, if you know the identifier of the resource you want to click, you can use solo.getView(R.id) to capture the object, and then use solo.clickOnView(View view) to click it.

+13
source

I found that the actual parameter of the method is not an identifier, but an β€œindex” when it matters. Therefore my way:

 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 } } } 
+1
source

Source: https://habr.com/ru/post/1438149/


All Articles