Create a UFT One automation script
Relevant for: GUI tests and components
Prerequisites
Decide whether to use UFT One Automation Scripts |
Creating a useful UFT One automation script requires planning, design time, and testing. Weigh the initial investment with the time and human-resource savings you gain from automating potentially long or tedious tasks. Any UFT One operation that you must perform many times in a row or must perform on a regular basis is a good candidate for a UFT One automation script. |
Choose a language and development environment |
You can write your UFT One automation scripts in any language and development environment that supports automation. For example: VBScript, JavaScript, Visual Basic, Visual C++, or Visual Studio .NET. For each language, there are a number of development environments available for designing and running your automation scripts. |
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 One Application object and starting UFT One in visible mode, using different programming languages
The example below can be used only after setting a reference to the type library. If you are 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 object
Set qtApp = New QuickTest.Application ' Create the object
qtApp.Launch ' Start QuickTest
qtApp.Visible = True ' Make it visible
Dim qtApp
Set qtApp = CreateObject("QuickTest.Application")
qtApp.Launch 'Start QuickTest
qtApp.Visible = True ' Make it visible
// Create the application object
var qtApp = new ActiveXObject("QuickTest.Application");
qtApp.Launch(); // Start QuickTest
qtApp.Visible = true; // Make it visible
#import "QTObjectModel.dll" // Import the type library
// Declare the application pointer
QuickTest::_ApplicationPtr spApp;
// Create the application object
spApp.CreateInstance("QuickTest.Application");
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 you choose a development environment that supports referencing a type library, you can take advantage of features like Microsoft IntelliSense, automatic statement completion, and status bar help tips while writing your script.
The UFT One automation object model supplies a type library file named QTObjectModel.dll. This file is stored in <UFT_One_installdir>\bin.
If you choose an environment that supports it, be sure to reference the UFT One type library before you begin writing or running your automation script.
Example: If you are working in Microsoft Visual Basic, select Project > Add Reference to open the Add Reference dialog box for your project.
Then select Unified Functional Testing <Version> Object Library (where <Version> is the current installed version of the UFT One automation type library).
Write your automation script
The structure for your script depends on the goals of the script. You may perform a few operations before you start UFT One such as retrieving the associated add-ins for a test or component, loading add-ins, and instructing UFT One to open in visible mode.
When opening a test or business component, UFT One dynamically loads its associated add-ins. For details, see Loading add-ins that were not loaded at startup.
After you perform these preparatory steps, if UFT One is not already open on the computer, you can open UFT One using the Application.Launch method. Most operations in your automation script are performed after the Launch method.
For details on the operations you can perform in an automation program, see UFT One Automation Object Model Reference (Help > Automation and Schema References > UFT One Automation Object Model Reference).
Tip: You can generate automation scripts from UFT One 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 your computer.
You can then run each generated script as is to instruct UFT One to open on other computers with the exact dialog box configuration defined in the generated script.
You can also copy and paste selected lines from the generated files into your own automation script.
For more details, see Generated automation scripts .
When you finish performing the necessary operations, or you want to perform operations that require closing and restarting UFT One (such as changing the set of loaded add-ins), use the Application.Quit method.
Run your automation script
There are several applications available for running automation scripts. You can also run automation scripts from the command line using Microsoft's Windows Script Host.
For example, you could use the following command line to run your automation script:
WScript.exe /E:VBSCRIPT myScript.vbs