How to Create an Automation Script

This task describes when and how to create automation scripts.

Prerequisites

  1. Decide whether to use OpenText Functional Testing Automation Scripts

    Creating a useful automation script requires planning, design time, and testing. You must always weigh the initial investment with the time and human-resource savings you gain from automating potentially long or tedious tasks.

    Any operation that you must perform many times in a row or must perform on a regular basis is a good candidate for a automation script.

  2. Choose a language and development environment for designing and running Automation scripts

    You can write your automation scripts in any language and development environment that supports automation. For example, you can use: 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.

Back to top

Create the Application object

The procedure for creating the Application object differs slightly from language to language. Below are some examples for creating the OpenText Functional Testing Application object and starting the testing application in visible mode, using different programming languages. For conceptual details on the Application object, see Application Object .

Visual Basic

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 application object

Set qtApp = New QuickTest.Application ' Create the application object

qtApp.Launch ' Start QuickTest

qtApp.Visible = True ' Make it visible

VBScript

Dim qtApp

Set qtApp = CreateObject("QuickTest.Application") ' Create the application object

qtApp.Launch 'Start QuickTest

qtApp.Visible = True ' Make it visible

JavaScript

var qtApp = new ActiveXObject("QuickTest.Application"); // Create the application object

qtApp.Launch(); // Start QuickTest

qtApp.Visible = true // Make it visible

Visual C++

#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

Back to top

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 OpenText Functional Testing automation object model supplies a type library file named QTObjectModel.dll. This file is stored in <Installdir>\bin.

If you choose an environment that supports it, be sure to reference the OpenText Functional Testing type library before you begin writing or running your automation script. For 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 or UFT One<Version> Object Library (where <Version> is the current installed version of the OpenText Functional Testing automation type library).

Back to top

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 the testing application, such as retrieving the associated add-ins for a test or component, loading add-ins, and instructing the application to open in visible mode.

Versions 15.0.1 and later: When opening a test or business component, its associated add-ins are dynamically loaded. For details, see the topic on working with add-ins in the OpenText Functional Testing Help Center.

After you perform these preparatory steps, if OpenText Functional Testing is not already open on the computer, you can open the application using the Application.Launch method. Most operations in your automation script are performed after the Launch method.

Tip: You can generate automation scripts from OpenText Functional Testing 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 OpenText Functional Testing to open on other computers with the exact dialog box configuration defined in the generated script, or you can copy and paste selected lines from the generated files into your own automation script. For details, see Generated Automation Scripts.

When you finish performing the necessary operations, or you want to perform operations that require closing and restarting OpenText Functional Testing (such as changing the set of loaded add-ins), use the Application.Quit method.

Back to top

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

For details on running automation scripts on a remote computer, see How to Run Automation Scripts on a Remote Computer .

Back to top