Forum Discussion

manish_bansal_1's avatar
manish_bansal_1
Occasional Contributor
11 years ago

Supress Object Not Found Error Optionally

 

I have an Application where a "Processing please wait..." dialog appears after a required operation and goes automatically after sometime as soon as processing is done, now i need to wait till this dialog is available on screen (sometime it remains open for more then 10 secs but other time 2 to 3 secs), so i do wait till the dialog is exists.

 

Do while (dialog.exist )

Loop

 

I want to Achieve this. 

 

1) if it exists, i keep on waiting, but as soon as dialog goes, move to the next step of varification.

2) if it exists more then 15 sec, seems there are some problem at message processing, do a dialog.close forcefully. and move to the next test case.

 

these above steps sound simple but not as easy to achive from TestComplete.

 

I am facing issues like.

 

1. as soon as dialog disappear say within 15 sec (I have a loop which is checking if dialog.exists breaks but test cases gets haulted for 30 secs - which is setup in the Project properties - 30 secs are crusial for testing in our case.)

 

2. sometime dialog remains open for more then 15 sec's but as soon as we try to close (dialog.close() ) them its already gone.

this thows exception - Object Not Found 

 

Can someone please help me in this case.

 

 

 

4 Replies

  • Manfred_F's avatar
    Manfred_F
    Regular Contributor

    Hi,

     

    to work with dialogs being closed, You have to evaluate not only the "exists'"-property, but also "visible". This is true, because Your Application Under Test may just make a dialog unvisible for the user before it is unloaded.

     

    Properly working with dialogs showing up occasionally or working with dialogs being closed requires some precautions.

    You want to read an object's property (e.g. "exists" or "visible"), but You can not assume for sure, that Your object actually still exists when You access that property (because it's being closed asynchronously by Your AUT). So You will get errors. This is a very basic task You have to solve, working with test automation.

     

    To cover this, I have got a function "hasPropertyValue(Object, PropertyName, RefValue)" doing the following:

     

    1- Set OptionsLocal.Run.Timeout to a small value, e.g. to 200ms from 10s. This is, because accessing the "exists" property waits for this timeout in case the object does not exist.

    2- Check, whether the "exists" property is supported by the object. If true,

    2.1- Check, whether the Object exists. If True,

    2.1.1- Check, whether the <PropertyName> property is supported by the object. If True,

    2.1.1.1- get the property's value, BUT: include it into script error handling AND suppress TC's writing the error to the log (possibly the object stopped existing since checking .exists).

    3- Compare the value with the reference

    4- Reset OptionsLocal.Run.Timeout to the previous value.

     

    So, to Check whether a dialog is still open, I call hasPropertyValue(myCtrl, "Visible", True) e.g. in a Do While block.

    For convenience, the hasPropertyValue function can be extended to accept subobject propertiy names as property name ("myObj.Systemmenu.Items.Count") and regular expressions as reference value.

     

    I hope this helps

     

    Manfred

     

    • manish_bansal_1's avatar
      manish_bansal_1
      Occasional Contributor

      Thanks for the writeup Manfred, 

       

      This is GrandFather Paradox situation , you can not call visible if object does not exists. (and the stupid tc will gift you another exception in logs :-P ) 

      I hope it makes  sense? 

      • Adrian_Tankard's avatar
        Adrian_Tankard
        Contributor

        You can use an error handler to ignore the exception.

        For example for VBScript&colon;

         

        on error resume next

        err.clear

         

            ' Insert code here to check if object is visible

         

        if err.number <> 0 then

            ' the object does not exist

        else

            ' the object exists

        end if

         

        ' turn off error handling

        on error goto 0

  • NisHera's avatar
    NisHera
    Valued Contributor

    I think best solution is to use For loop

    withing that use your do while

    eg

    for(i=0;i<10;i++){
           Do while (dialog.exist )
              //use minimum wait time
           Loop
       if (!dialog.exist) {
            return
        }
    }