Check Boxes in Android can be tested using Robotium. The following are different functions supported by Robotium to check the Checkbox functionality.
- getCurrentCheckBoxes()
- isCheckBoxChecked(int index)
- isCheckBoxChecked(String text)
- clickOnCheckBox(int index)
The Activity contains three checkboxes, let us write some sample code to test them.
Test case for Android Check Boxes :
Steps :- Click on the Check box ‘Android’
- Click on the Check box ‘iPhone’
- Verify the Status of check boxes
- Unselect the Checkboxes ‘iPhone’ and ‘Android’
- Verify the Status again
public void testCheckBoxes() throws Exception {
solo.waitForActivity("MainActivity");
//click on Image Button
solo.clickOnImageButton(0);
//look for checkbox text
actual = solo.searchText("Windows");
assertEquals("Windows text not found",true, actual);
//select checkbox Android
solo.clickOnCheckBox(0);
//select checkbox iPhone
solo.clickOnCheckBox(2);
//check the Status of checkbox 'Android'
boolean actual1 = solo.isCheckBoxChecked(0);
assertEquals("Android is not Selected",true, actual1);
//check the Status of checkbox 'iPhone'
boolean actual2 = solo.isCheckBoxChecked(2);
assertEquals("iPhone is not Selected",true, actual2);
// unselect Android and iPhone
solo.clickOnCheckBox(0);
solo.clickOnCheckBox(2);
//check the status again
actual1 = solo.isCheckBoxChecked(0);
assertEquals("Android OS is Selected",false, actual);
actual2 = solo.isCheckBoxChecked(2);
assertEquals("iPhone is Selected",flase, actual2);
}
- Select/Unselect Checkbox : ‘solo.clickOnCheckBox()’ can be for both Select and Unselect checkbox. First time, when used this function, it will select the option and second time when performed the same action, it will unselect the Checkbox.
- Verify the Status of Checkboxes : ‘solo.isCheckBoxChecked()’ function is used to verify the status of Checkbox. function returns ‘true’, if it is selected and ‘false’ otherwise.
- Please note that, in the assert statements, while verifying the status of unselected check boxes, we used the expected result as ‘false’.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.