Robotium supports various APIs to test Android Toggle Button functionality
the following are some of the APIs supported by Robotium to test the Toggle Buttons
Let us write a test case for the Example project shown on the Right side, which has one toggle buttonthe following are some of the APIs supported by Robotium to test the Toggle Buttons
- searchToggleButton(String text)
- clickOnToggleButton(String name)
- isToggleButtonChecked(int index)
- isToggleButtonChecked(String text)
Test case for testing Toggle Button :
Steps:- Search for the Toggle Button
- Assert True/False based on the search result
- Click on the Toggle Button
- Check if Toggle Button status is changed or not?
- Click on the Toggle Button again
- Check whether the Toggle Button status is changed or not?
1: public void testToggleButton() throws Exception {
2: solo.waitForActivity("MainActivity");
3:
4: //search for toggle button
5: actual = solo.searchToggleButton("OFF");
6: assertEquals("Toggle Button not found",true, actual);
7:
8: //Turn ON toggle button
9: solo.clickOnToggleButton("OFF");
10: actual = solo.isToggleButtonChecked(0);
11: assertEquals("Toggle Button is OFF",true, actual);
12:
13: //Turn OFF toggle button
14: solo.clickOnToggleButton("ON");
15: actual = solo.isToggleButtonChecked(0);
16: assertEquals("Toggle Button is ON",false, actual);
17:
18: }
- Search for Toggle Button : ‘solo.searchToggleButton()’ is used to search for toggle buttons in the current activity
- the functions returns ‘true’ if the Toggle Button with the given string is found otherwise return ‘false’
- Click on the Toggle Button : ‘solo.clickOnToggleButton()’ is used to click on Toggle Button with the given string
- on enabling the Toggle Button, it’s text is changed from “OFF” to “ON”. hence, second time we modified the search pattern to “ON”
- Check the Status of Toggle Button : ‘isToggleButtonChecked()’ is used to check the status of Toggle Button
- argument passed can be a String or Index
- returns true if the toggle button is checked, otherwise, return false.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.