How to create automation scripts for Unified Functional Testing (UFT).
o Decide whether to use UFT Automation Scripts
Creating a useful UFT automation script requires planning, design time, and testing. It must always weigh the initial investment with the time and human-resource savings it is gain from automating potentially long or tedious tasks.
Any UFT operation that must be performed many times in a row or must perform on a regular basis is a good candidate for a UFT automation script.
- Choose a language and development environment for designing and running Automation scripts
For each language, there are a number of development environments available for designing and running automation scripts.
2. Create the Application object
The procedure for creating the Application object differs slightly from language to language. Below are some examples for creating the UFT Application object and starting UFT in visible mode, using different programming languages.
The example below can be used only after setting a reference to the type library. If not working in a development environment that allows referencing type libraries, create the Application object as described for VBScript below.
Dim qtApp As QuickTest.Application ‘ Declare the application object
Set qtApp = New QuickTest.Application ‘ Create the application object
qtApp.Launch ‘ Start QuickTest
qtApp.Visible = True ‘ Make it visible
Set qtApp = CreateObject("QuickTest.Application") ‘ Create the application object
qtApp.Launch ‘Start QuickTest
qtApp.Visible = True ‘ Make it visible
var qtApp = new ActiveXObject("QuickTest.Application"); // Create the application object
qtApp.Launch(); // Start QuickTest
qtApp.Visible = true // Make it visible
#import "QTObjectModel.dll" // Import the type library
QuickTest::_ApplicationPtr spApp; // Declare the application pointer
spApp.CreateInstance("QuickTest.Application"); // Create the application object
spApp->Launch();// Launch the application
spApp->Visible = VARIANT_TRUE; // Make it visible
- Reference the type library – optional
Some development environments support referencing a type library. A type library is a binary file containing the description of the objects, interfaces, and other definitions of an object model.
If choosing a development environment that supports referencing a type library, it can be used the advantage of features like Microsoft IntelliSense, automatic statement completion, and status bar help tips while writing the script. The UFT automation object model supplies a type library file named QTObjectModel.dll. This file is stored in <Unified Functional Testing installation folder>bin.
If an environment that supports it is chosen, be sure to reference the UFT type library before begin writing or running the automation script. For example, if working in Microsoft Visual Basic, select Project > Add Reference to open the Add Reference dialog box for the project. Then select Unified Functional Testing <Version> Object Library (where <Version> is the current installed version of the UFT automation type library).
- Write the automation script
The structure for script depends on the goals of the script. It might be performed a few operations before starting UFT such as retrieving the associated add-ins for a test or component, loading add-ins, and instructing UFT to open in visible mode.
After performing these preparatory steps, if UFT is not already open on the computer, UFT can be opened using the Application.Launchmethod. Most operations in automation script are performed after the Launch method.
Tip: Automation scripts can be generated from UFT that contain the settings for the Test Settings dialog box, the GUI Testing tab in the Options dialog box, and the Object Identification dialog box as they are set on the computer. Then each generated script can be run as is to instruct UFT to open on other computers with the exact dialog box configuration defined in the generated script, or copying and pasting selected lines from the generated files into own automation script.
When finish performing the necessary operations, or wanting to perform operations that require closing and restarting UFT (such as changing the set of loaded add-ins), use the Application.Quit method.
- Run the automation script
There are several applications available for running automation scripts. It is possible also to run automation scripts from the command line using Microsoft’s Windows Script Host.
For example, the following command line can be used to run the automation script:
WScript.exe /E:VBSCRIPT myScript.vbs