navigation
 Sunday, March 16, 2008

An another FAQ asked question about TestComplete is "Why when I check the Exists property of my [Insert UI element here] do I get an error message in the Test Log?".  For Example given the code:

If (Sys.Process("MyApp").Window("#32770","Error").Exists)  //Error here :(
{
// Do Something here
}

The user wants to check for the error dialog and only do something if it exists, but it is not a failure of the test if the error dialog does not show up (in fact it is a good thing). The #32770 wndclass is a standard dialog wndclass of Windows.

Part of the problem is not understanding, how and where the error message that TestComplete post comes from.  So let us breakdown part of the code above and explain what is happening internally in TestComplete (with some simplifications).  The part of the code we will examine is "Sys.Process("MyApp").Window("#32770","Error").Exists".  Starting from the Sys object, we call the Process method.

  • Process("MyApp") - Calling the Process method of the Sys object, TestComplete will take a look at the running processes (applications) and try to find one named "MyApp", if more than one "MyApp" is running, TestComplete returns the first one (since we have not told TestComplete which one we want).  If the application is not running, TestComplete checks any newly launched applications for a match up to the Auto-timeout period set by the project (default is 10 seconds). If, after the Auto-timeout, the application is still not running, TestComplete post an error to the Test Log, and the Process method returns a null object.  Otherwise, since the application was found, the Process method returns a Process object which is used for the next part.
  • Window("#32770","Error") - Calling the Window method of the Process object, TestComplete will look at all the child objects for a window with the WndClass of "#32770", if the WndClass matches, TestComplete will then check the WndCaption to see if it matches.  If one or more windows match, TestComplete will return the first one (since we have not told TestComplete which one we want), otherwise TestComplete waits and checks any newly created Windows for a match (up to the Auto-timeout period).  If a match is found, the Window method returns a Window object (used for the next part). Otherwise, TestComplete will post an error message to the Test Log, and the Window method returns a null obect.
  • Exists - If you have got here without an error in the Test Log (and the using the above code), you will get the value of true. Now, if you try to call Exists on the null object, you will get a script error about trying to get a non-existent property.

Now, hopefully you have a better understanding of why and where the error message is happening.  Of course, this does not explain how to check for the existents of an UI element without posting an error.  This is accomplished by using a Wait... method.  For example, WaitWindow("#32770","Error",-1,5000),  this will wait up to five seconds (5000 ms) for the Window.  It will return the Window object if found in that time, otherwise it will return a Stub object. The Stub object has one property, which is Exists and is set to false.

BTW, you can return your own Stub object by using the Utils.CreateStubObject() method.

Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, i, strike, u) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview