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.

About Meir Bar-Tal

Meir Bar-Tal is an Automation Architect with extensive technical, educational and leadership experience in Software Design, Development and Testing. For many years Meir has helped companies establish solid foundations for their testing activities with a wide variety of software applications and systems and across different technologies and platforms. Meir is a well-known expert in Data-Driven, Keyword Driven and Hybrid methodologies and has published a number of influential articles on the applications of Design Patterns to Test Automation. For the last five years, he has been pushing forward an ambitious program towards the development of an Object Oriented automation framework named Sunscrit, a huge project which is still underway. Meir is the owner of www.AdvancedQTP.com of which he was a co-founder in 2007 and served as its Editor in Chief, Author and Forums Administrator ever since. Meir lives in Israel and cooperates closely with HP R&D and other colleagues to improve the user experience and productivity with HP Software tools.