«

Jul 20 2017

What’s App, UFT?

Customer tales: An exception a developer got while debugging a script disclosed undocumented UFT global object: App. This short article presents the lesson learned and defines what’s App actually ☺

A common (but wrong) practice is the use of variables without defining them first, which is allowed by VBScript, but may cause trouble at runtime. The simplest way to prevent such malpractice is by including at the beginning of the Action or function library the following statement
Option Explicit
So that any usage of an undefined identifier would prevent the script from running (unless you also add the statement On Error Resume Next, but fail to handle the exceptions). For example, you could get an error message as the following:

Image VarIsUndefined

 

 

 

 

 

Failing to declare Option Explicit may result in runtime errors and problems as in the following cases:

  1. A variable is assigned a value but is undefined (see above)
  2. A variable is assigned a value but referred incorrectly afterwards (for example, username = “Bill” and then If(uesrname <> “”)Then
  3. A variable is referred to but takes its value from a global scope variable.

The last one is especially important in the context of automation tools and UFT in particular. In one case I found that an automation developer used the following code within the scope of an Action:
Set App = CreateObject("Quicktest.Application")
'More code followed
This worked well, but then in order to make the code reusable she decided to put it in a function library. After doing this and attaching the library to the test, she got a runtime error on one of the lines, stating that “the object does not support this method or property”. The code remained the same, so what was the problem? It turned out that UFT has a global scope App object of type IGenCollection, and when the code was transferred to a Subroutine in the library, in the absence of a local definition for the variable App, the Sub defaulted to referring to the global scope object.

It is a pity that UFT doesn’t warn us of such possible issues (and there’s a lack of technical documentation as to such global scope variables), but the lesson we must learn is that using strictly defined variables (forcing it with Option Explicit) is a must, and also that it is advisable to have their names given according to standard conventions. Hence, if instead of App the variable had been defined as qtApp (which helps us understand what App it was intended to refer to), the issue would not have arisen.