Use an Action from one script in another script

Insert a call to such source action using any of the following methods:

  • QTP Graphical User Interface (GUI):

1. Go to Insert menu, then select "Call to Existing Action" (or "Call to Copy of Action")

Note: A "Call to Existing Action" inserts a link to the Action in the original script. A "Copy of Action" inserts a copy of the Action into the new script.

2. Browse to the first script in the "From test" field.

3. Select the Action(s) you want.

4. Select the location where the Action should be inserted.

5. Click <OK>.

  • Programmatically. Starting with QuickTest Professional 10.0, the statementLoadAndRunActionwas implemented, loading during run-time the dedicated resources of a reusable action to main test.

    LoadAndRunAction "C:\MyTest", "Action1", OneIteration

Considerations:

By design, an Action has dedicated resources used during replay, specifically a script, a local repository (can only be modified directly from source test storing the action) and a Data table sheet (only one denominated as "local sheet", not "global sheet") with same name as action (name of source test script is displayed between brackets).

Action’s Data Table Sheet Notes:

  • Iterations: Action will iterate X amount of times after desired configuration from "Action Call Properties" dialog (right click on action under Test Flow Pane), under "Run" tab. To run action depending how many rows sheet has, setup "Run on all rows" for "Data Table iterations" option.
  • Access to data on sheet: When script is running through an action’s code, this sheet can be accessible by using statements such as

    DataTable.GetSheet(dtlocalsheet).GetCurrentRow

    Or

    DataTable("A", dtlocalsheet) = CSTR(Now)

Advertisements

Files and subfolders of a QuickTest Professional test

The files and folders hold binary and text data that are required for the test to run successfully

The following table provides a description, the type, and comments regarding the files that make up a QuickTest Professional test.

File Name Description Type Comments Regarding File
Test.tsp Test settings Binary Do not edit
Default.xls Data table parameters Excel similar Can be edited using Excel
Parameters.mtr Parameterization information Binary Do not edit
Action<I> Action folder (See other table)
Default.cfg Load test configuration file Text Do not edit
Default.prm Load test configuration file Text Do not edit
Default.usp Load test configuration file Text Do not edit
<testname>.usr Load test configuration file Text Do not edit
Thick_usr.dat Load test configuration file Text Do not edit
Thin_usr.dat Load test configuration file Text Do not edit

Files within Action folder:

File Name Description Type Comments Regarding File
Script.mts Action script Text Edit text preceding the @@ sign only
Resource.mtr Object Repository Binary Do not edit
Snapshots Active screen files Folder Do not edit

Associate Shared Object Repositories to the test (QTP 9.0)

Associating Shared Object Repositories (QTP 9.0)

With QuickTest Professional 9.0, you can associate multiple Shared Object Repositories with each action. Each action will always be associated with a Local Object Repository and can also be associated with one or more Shared Object Repositories.

Note:
All Shared Object Repositories are associated at the action level, not the test level, in QuickTest Professional 9.0. If you open a test that was created with an earlier version of QuickTest Professional, the Shared Object Repository will be associated with all of the test’s actions automatically.

Associating Shared Object Repositories with an action:
1. Right-click on the action, and select "Action Properties."
2. Select the Associated Repositories.
3. Click the "Adds a new shared object repository file to the list" button (with the + icon).
4. Browse to and select the desired Shared Object Repository.
5. Repeat steps 3 and 4, as needed.
6. If needed, move the selected repository files up and down in the list using the arrow buttons.

Associating Shared Object Repositories with multiple actions in one script:
1. Go to Resources -> Associate Repositories.
2. In the Associate Repositories dialog, click the "Add Repository" button (with the + icon).
3. Browse to and select the desired Shared Object Repository file.
4. Repeat steps 2 and 3 as needed for all Shared Object Repository files.
5. Select one of the repository files.
6. In the Available Actions list, select the actions the Shared Object Repository should be associated with.
7. Click the ">" button. The selected actions will move to the Associated Actions list. If you want to associate the file to all actions, click the ">>" button.
8. Repeat steps 5 through 7 for all repository files in the list.
9. Click <OK>.

Associating Shared Object Repositories with all new actions:
1. Right-click on the action, and select "Action Properties."
2. Select the Associated Repositories.
3. Click the "Adds a new shared object repository file to the list" button (with the + icon).
4. Browse to and select the desired Shared Object Repository.
5. Repeat steps 3 and 4, as needed.
6. If needed, move the selected repository files up and down in the list using the arrow buttons.
7. Click <Set as Default>.
8. Click <OK>.

How to call functions from a function library

Using a function library

QuickTest Professional does not support declaring functions in one Action and using them in another Action.

If you include your functions in a loaded library written in VBScript, you may call those functions from any location in the test. This is particularly useful when you want to reuse code that performs certain steps.

You call a function procedure using the function name, followed by the argument list. If your function returns a value, the argument list should appear within parentheses.

QuickTest Professional 6.0 or higher
1. Create the function library file.
2. Associate the function library with the test script. For information on associating a function library, refer to Document ID 46019 – How to associate a function library with a test.
3. Call the function in the script, as needed.

Example:
‘ Function library is loaded in File -> Settings -> Resources tab.
‘ Call the MakeReverseUpper function.
RevName = MakeReverseUpper ("Homer")
MsgBox RevName

To enter a function call using the Keyword View, use the Step Generator. If you have registered the function to a QuickTest Professional Test Object (using RegisterUserFunc), you will call the function as you would a built in QuickTest Professional test method.

QuickTest Professional 5.6 or below
1. Create a FileSystemObject.
2. Open the library file.
3. Read the file in to a variable.
4. Execute the library code (within the variable).

The following example illustrates the use of a function that converts a string to uppercase and reverses the order of the letters.

Example:
‘ Test script:
Dim fso, f, libcode, RevName

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("C:\Libcode.txt", 1)
libcode = f.ReadAll

Execute libcode

RevName = MakeReverseUpper ("Homer") ‘ Function returns "REMOH"

MsgBox(RevName)

‘ Function Library (Filename: C:\Libcode.txt)
Function MakeReverseUpper (s)
rev = StrReverse (s)
MakeReverseUpper = UCase (rev)
End Function

Automation Object Model (AOM) statements be executed within a script

The Automation Object Model (AOM) was designed to be used outside of QuickTest Professional (QTP) / Unified Functional Testing (UFT)and not within a script (during replay).

Note:Some AOM statements may run in a script; others will generate errors. The AOM should not be used within a script tochange settings during the script execution.

If it were needed to change QTP/UFT’s settings using AOM statements, create a .VBS file to launch QTP/UFT and execute the test scripts.

Automation Object Model (AOM) in QTP/UFT

The QuickTest Professional (QTP) / Unified Functional Testing (UFT) Automation Object Model (AOM) is an application programming interface (API) designed to write programs that automate your QTP/UFT operations. The AOM provides objects, methods, and properties that enable you to control QTP/UFT from another application.

The AOM enables you to automate test management.

You can control virtually every QTP (UFT-GUI) feature and capability using the objects, methods and properties included in the Automation Object Model. Automation scripts make it easy to perform any QuickTest operation multiple times in multiple tests without having to open the QTP/UFT application, for example,

  • You can write a script that modifies the test object description properties in the Object Identification dialog box and performs an update run on all tests in a specified file folder.
  • After installing a new add-in, an automation script can associate this add-in to all relevant tests.
  • You can write an automation script to run a selected batch of tests. For each test, you can retrieve the associated add-ins list. Then, if the necessary add-ins are not already loaded, you can close QTP/UFT, load the necessary add-ins, reopen QuickTest, and run the test.
  • You can define your settings for a test in QTP/UFT, then click "Generate Script" in the Generate tab of the Test Settings dialog box to generate an automation script based on the current test settings. You can then apply those same settings automatically to multiple tests using the whole automation script or excerpts from the generated file.

Example: Create and run an automation program from Microsoft Visual Basic that loads the required add-ins for a test, starts QTP/UFT in visible or minimized mode, opens the test, configures settings that correspond to those in the Options, Test Settings, and Record and Run Settings dialog boxes, runs the test, and saves the test.

Creating automation programs:
The Properties tab of the Test Settings dialog box, the General tab of the Options dialog box, and the Object Identification dialog box each contain a "Generate Script" button. Clicking this button generates a automation script file (.vbs) containing the current settings from the corresponding dialog box.

You can run the generated script as is to open QTP/UFT with the exact configuration of the QTP/UFT application that generated the script, or you can copy and paste selected lines from the generated files into your own automation script.

Generating an automation script for QTP/UFT options:

1. Go to Tools -> Options.

2. Select the General tab.

3. Click <Generate Script>.

4. Save the script to the desired location.

5. Click <OK> to close the Options dialog.

Generating an automation script for test settings:

1. Go to Test -> Settings.

2. Select the Properties tab.

3. Click <Generate Script>.

4. Save the script to the desired location.

5. Click <OK> to close the Test Settings dialog.

Generating an automation script for object identification settings:

1. Go to Tools -> Object Identification.

2. Click <Generate Script>.

3. Save the script to the desired location.

4. Click <OK> to close the Object Identification dialog.

The QTP/UFT Automation Object Model Reference file is a help file that provides detailed descriptions, syntax information, and examples for the objects, methods, and properties in the QuickTest Automation Object Model.

When QTP/UFT is installed is possible to open the Automation Object Model Reference from:

  • The QTP/UFT program folder (Start -> Programs -> QTP/UFT -> Documentation -> Automation Object Model Reference)
  • The QTP/UFT Help menu (Help -> Automation Object Model Reference)

Load/associate a function library (vbs, txt, qfl) for use with a script

  • Via User-Interface. Note: this approach loads the associated function library’s contentsbefore loading/reading the Test’s actions
    • Via Test’s Settings (all versions):

1. Navigate to QTP’s File menu and select "Settings" option

2. Access the "Resources" tab

3. Under the "Libraries" section’s listing "Associated Function libraries", click the "+" sign (plus)

4. Type the path of the desired file (or browse to find it)

5. Click "Apply" and/or "Ok"

6. Save test

  • Via "Resources" panel (QTP 9.5 – QTP 11):

1. Access the panel by enabling it under QTP’s View menu

2. Once displayed, right click on top option "Associated Function Libraries" and select given option

3. Select the desired file, and click on "Open"

4. Save the test

  • Via "Solution Explorer" pane (UFT 11.5 and above):

1. Display the Solution Explorer pane (View > Solution Explorer)

2. Right-click the GUI test node and select "Add > Associate Function Library", or right-click the "Function Libraries" node within the relevant test’s node in the tree and select "Associate Function Library".

3. Select the desired file, and click on "Open"

4. Save the test

  • Programmatically (run-time/running-testscript). Depending on the version of QTP (or UFT), there are 2 coding statements:

    Note: This approach loads and makes available the contents of function library, after running below statements

    (Important) Library files should not have syntax errors(by opening library file with QTP, then using Ctrl+F7 or "Check Syntax" option under QTP > Tools) before running scripts where files get loaded dynamically. These programmatic statements don’t validate the possibility of syntax errors, therefore possibly causing functions not being loaded/found as well given unexpected errors.

·

  • ExecuteFile. It loads the contents of library files, BUT it doesn’t associate them to test. Note: this option doesn’t allow debugging visually line by line a running code, because the execution marker (yellow arrow on the left displayed on left margin of code when running a script) points can’t point to correct line, which can end up pointing to blank/commented or even wrong lines when reporting an error of such files.

    ExecuteFile "C:\MyLibraries\MyLibrary.qfl"

  • LoadFunctionLibrary. Associates and load the contents of a library to running memory of the script. Offered starting QTP version 11, to dynamically associate function libraries (vbs, qfl, txt) to a currenlty running test. Deprecates "ExecuteFile" since it allows debugging step-by-step execution, displaying the correct line running (and displaying line number and contents when erroring out)

    LoadFunctionLibrary "C:\MyLibraries\MyLibrary.qfl"

Via Automation Object Model (AOM – QTP API). The AOM feature offers Libraries property (a collection object of type "TestLibraries") as part of the Test object properties. For users to implement its usage, it is necessary to create a VBScript file with required statements and execute (by double clicking file)Note: Any AOM implementation is only supported outside QTP (not executed by QTP).Set QTP = CreateObject("QuickTest.Application") QTP.Launch QTP.Visible = True QTP.Open "C:\Tests\Test1", False, False QTP.Test.Settings.Resources.Libraries If QTP.Test.Settings.Resources.Libraries.Find("C:\Utilities.vbs") = -1 Then QTP.Test.Settings.Resources.Libraries.Add "C:\Utilities.vbs", 1 End If QTP.Test.Save ‘ Save the test QTP.Quit ‘ Quit QuickTest Set QTP = Nothing