Test Suite Script Example | TestFort

Script Example: BH Test Suite

You are here

This script was used to test a Palm application.

This script executes index one time. Then, when appearing on the form checks whether this form was tested before or not. If not, then it takes the ScreenShot, ControlState, CRC and FormID and records these data into the array. This script also checks all fields and checkboxes. By the end of script execution these data are recorded into log. Then all of the elements and button IDs existing on the form are recorded into the temporary array. After that array index is randomly selected and the appropriate button is pushed on Palm OS device.

TestFort Test Suite Sample Script

function Test(sApp,iIndex)
{
   //Array, where form IDs are stored
   var arrFormID=new Array();

   //Temporarily array for buttons which exist on the form
   var arrTmpBtn=new Array();

   //Array with IDs of all buttons, which were pushed
   //during script execution
   var arrButton=new Array();

   //This array collects all button IDs from the forms,
   //where the script has already been before. It means that
   //the IDs of all tested forms are stored in this array
   var arrExtButton=new Array();
   Log.PutString("Test for "+ Environment.DeviceType() +
                 " OS " + Environment.OSVersion(),0);
   appLaunch(sApp);
   for(var i=0 ; i<iIndex ; i++)
   {  
      //Shows the message about test number which disappears
      //in 2 seconds, if the tester does not click on it
      Alert2("Function Test", "Test ¹ "+i, 2, 0);

      //Flag is used to skip the testing of some forms where
      //the script has been before
      var bFlag;  

      //Variable stores the quantity of buttons on form
      var iBt=0;

      //Checks, whether this form was tested before or not
      bFlag=CompareFormID(arrFormID);

      //If the form was not tested before, then the script
      //checks the fields
      if(bFlag)
      {
         //Array for storing error messages
         var arrArray=new Array();
         TestFields(arrArray, 0);
         
         //Logs the messages from arrArray array
         ArrayToLog(arrArray, "Test Fields", 1);

         //Zeroizes the array
         arrArray.length=0;

         //Checks all checkboxes on form
         TestCheckBox(arrArray, 0);
         ArrayToLog(arrArray, "Test CheckBox",1);

         //Zeroizes the array
         arrArray.length=0;

         //Checks how many buttons are on the form
         iBt=GetBtn(arrTmpBtn);

         //Records IDs of all buttons from this form to extButton
         //array
 TmpToExtArray(arrTmpBtn, arrExtButton, iBt);
      }
      else
      {
         if(ExtToTmpArray(arrExtButton,arrTmpBtn))
            iBt=arrTmpBtn.length;
         else
         {
            //Checks the quantity of buttons on form
            var iBt=GetBtn(arrTmpBtn);

            //Records all button IDs from the form to extButton
            //array
    TmpToExtArray(arrTmpBtn, arrExtButton, iBt);
         }
      }

      if(iBt!=0)
      {
          //Inputs large quantity of buttons to all fields (not more than 50)
          //and does not perform button pushing. Then pushes a random button      
          var arrArray=new Array();
          GetFields(arrArray);
          BigWord(arrArray, 0, 50);
          while(true)
          {
             //Generates a random index for array of buttons  
             //existing on active form
             var iRand= Rand (iBt-1);
             var iTemp=Control.GetFormID();
             //If the button push is performed successfully
             //then script exits from the cycle
             if(Control.Select("##"+arrTmpBtn[iRand],""))
             {
                arrButton[arrButton.length]="##"+arrTmpBtn[iRand];
                //Exits the cycle only if going to another form
                if(Control.GetFormID()!=iTemp)
                 break;
             }
          }
          //Zeroizes temporarily array
          arrTmpBtn.length=0;
       }
       else
       {
          
          PutInLog(arrFormID);
          ArrayToLog(arrButton,"All buttuns");
          Log.PutString("No buttons on form",0);
          return;
       }
      
   }
   PutInLog(arrFormID);
   ArrayToLog(arrButton,"All buttuns",10);

}

//------------------------------------------------------------