Friday, December 28, 2012

Use Robotium to test Android Progress bar, Seek bar and Rating bar

Robotium Supports various functions to support Progress bar, Seek bar and Rating bar. it uses the following functions to support these views.
  • getCurrentProgressBars()
  • setProgressBar(int index, int progress)
  • setProgressBar(android.widget.ProgressBar progressBar, int progress)
setProgressBar(), is the one function, which can set the progress of Progress bar, Seek bar and Rating bar.
Let us see one example Test case to the sample project shown on the Right side,

Test case for Progress Bar :

Steps:
  1. Set the Progress bar status from Zero to High
  2. Set the Seek bar position from Minimum to Maximum
  3. Set the Rating Bar from 1 start to 5 stars
Test Code :
   1: public void testProgressBar() throws Exception {

   2:  

   3:      solo.waitForActivity("MainActivity");

   4:      // set the Progree Bar Status

   5:      solo.setProgressBar(0, 10);

   6:      solo.setProgressBar(0, 20);

   7:      solo.setProgressBar(0, 30);

   8:      solo.setProgressBar(0, 40);

   9:      solo.setProgressBar(0, 50);

  10:      solo.setProgressBar(0, 10);            

  11:     // set the Seek Bar Position  

  12:      solo.setProgressBar(1, 10);

  13:      solo.setProgressBar(1, 20);

  14:      solo.setProgressBar(1, 30);

  15:      solo.setProgressBar(1, 40);

  16:      solo.setProgressBar(1, 50);

  17:      solo.setProgressBar(1, 10);

  18:     // set the Rating Bar status  

  19:      solo.setProgressBar(2, 2);

  20:      solo.setProgressBar(2, 3);

  21:      solo.setProgressBar(2, 5);

  22:      solo.setProgressBar(2, 7);

  23:      solo.setProgressBar(2, 9);

  24:      solo.setProgressBar(2, 10);

  25: }

Explanation :
  1. Set the Progress bar and Seek bar position : ‘solo.setProgressBar()’ is used to set the position of status bar, the position has to be specified in Integer number say 10,20,30,40 so on.. i hope max value is 100. just, try with different numbers and see the change in position.

  2. Set the Rating bar : ‘solo.setProgressBar()’, is used to set the Rating bar. use the numeric value from 1 to 10.

  3. Since there are 3 similar items(Progress bar, Seek bar and Rating bar), index will starts from 0 to 2.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.