Showing posts with label buttons. Show all posts
Showing posts with label buttons. Show all posts
Friday, September 15, 2017
Using Robotium to test Android Toggle Buttons
Using Robotium to test Android Toggle Buttons
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 button
the 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.
download file now
Tuesday, September 5, 2017
Use Robotium to test Android Image Buttons
Use Robotium to test Android Image Buttons
As it is common that most of the Android developers will use Image Buttons instead Text buttons, it is important criteria to test Image buttons.

Robotium has support for Image Buttons. The following APIs can be used to test Image Button functionalities,
Explanation :

Robotium has support for Image Buttons. The following APIs can be used to test Image Button functionalities,
- getImageButton(int index)
- clickOnImageButton(int index)
Test case for Image Buttons :
Steps :- Click on the Image Button �Alarm�
- go back
- Click on the Image Button �Music�
1: public void testCheckBoxes() throws Exception { 2: solo.waitForActivity("AlarmPlusActivity"); 3: 4: //click on Alarm Image Button 5: solo.clickOnImageButton(0); 6: assertTrue(solo.searchText("Add alarm")); //this text appears in the next activity 7: //go to previous screen 8: solo.goBack(); 9: //click on Gallery button 10: solo.clickOnImageButton(1); 11: 12: }Explanation :
- Click on Image Button : �solo.clickOnImageButton()�, is used to click on the Image button, which accepts only index number as argument.
- Return to Previous screen, �solo.goBack()�, is used to go to Previous screen.
- index of the Image buttons increase from Left to Right. Alarm button has 0, Gallery button has 1 and Home button with index
download file now
Subscribe to:
Posts (Atom)