Forum Discussion
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_111 years agoOccasional 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_Tankard11 years agoContributor
You can use an error handler to ignore the exception.
For example for VBScript:
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