Forum Discussion

BrandonH's avatar
BrandonH
Contributor
8 years ago

Wait loop until no error

I'm trying to do the following to determine when a process has completed:

 

while (equals(i,false))

{

 i = true;

try {

     ListViewObject.ClickItem(0,"COMPLETE");

}

catch (err)

{

i = false

}

 

}

 

However, even though an error is thrown in the TestComplete log and the next iteration of the loop continues, catch is never enacted and "i" is never set to false.   What gives?

 

 

4 Replies

  • NisHera's avatar
    NisHera
    Valued Contributor

    You are dealing with two type of errors.

    1) programming errors - which will fire when program con not run for any kind of error. eg "var x = 1/0"

    2) testing error - Those are errors that you tester and TC thinks and error eg "Age of employee = 500 years"

            employee_Age = 500
            if (employee_Age>75){
              Log.Error("he/she should be retired ")
            } 

     

    still you can make script to interdependent those errors. eg if  Age of employee>75 years then var x = 1/0

     

    try catch will catch programming errors not TC errors.....

    in your code first i fails 

    then you make it true ....so the loop run .........

    even "ListViewObject.ClickItem(0,"COMPLETE");" fails it is a TC error not programming error 

     

    hence you have to raise an error for the code .. "ListViewObject.ClickItem(0,"COMPLETE");

    you can do that adding this code just below that line......

         if (!(parentObject.WaitChild(ListViewObject, 500).exist)){
            throw new UserException('ListViewObject not found');
         } 

    p.s. replace parentObject from your actual parent object 

    • BrandonH's avatar
      BrandonH
      Contributor

      I attempted the following:

       

      try {

      if (equal(ListViewObjectParent.WaitChild(ListViewObject.ClickItem(0,"COMPLETE"),500)),false)

      {

           throw err

      }

       

      }

      catch (err)

      {

           i = false

      }

       

      however, the script errors saying it can not find list view subitem "COMPLETE" and does not enter the catch.  Furthermore, instead of passing over the errors due to the try, it now fully stops script execution.  How do it enter the catch statement on failure?

       

       

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        Change your code to:

         

        try {
        var childObject = ListViewObjectParent.WaitChild('ListViewObjectName', 10000)
        if (!childObject.Exists) {
        throw err
        }
        childObject.ClickItem(0, "COMPLETE); 
        }
        catch (err)
        {
             i = false
        }
        
        

        You need to detect the existance of the child object first before you attempt to click on it.  Replace 'ListViewObjectName' with the string in the "Name" property of the object.

  • shankar_r's avatar
    shankar_r
    Community Hero

    If an item not founds in the DropDown, it will display an error saying item doesn't exist.These type of error will catch by try...catch method. Hence i never going to be false unless until any run time error occurs.

     

    Scenario you are trying here, I'm not sure what the flow.