Automation Object Model in UFT One (AOM)

Automation Object Model in UFT is a way to automate UFT itself using the COM interface. The automation object model is a set of objects, methods, and properties that can be used to control the configuration settings and execute the scripts using the UFT interface. You can accomplish various things using UFT Automation Object Model. The list is very long, but here are a few examples.

Automation object Model in UFT

 

Load the required add-ins for a Test using Automation Object Model in UFT

Example: The following example shows loading the required add-in for the Test and launch the UFT with the visible mode and open an existing Test and run it.

Run UFT in Minimized Mode Using Automation Object Model in UFT

To Run UFT in the minimized mode use the following syntax
qtApp.WindowState = “Minimized”
 
And to run UFT in maximized mode use the following syntax
qtApp.WindowState = “Miximized”
 

Associate Required Object Repositories using Automation Object Model in UFT

We can associate the required repository with an action using the following syntax
qtApp.Test.Actions(“Action Name”).ObjectRepositories.Add “<Repository Path>”

Associate Required Function Libraries Using Automation Object Model in UFT

To associate a function library with a Test using UFT Automation Object Model we can use the following code
Syntax
qtApp.Test.Settings.Resources.Libraries.Add(“<Func Lib Path>”)

Set the Common Object Sync Time Out Using Automation Object Model in UFT

We can set the Object Sync Time out using the following Syntax
Syntax
qtApp.Test.Settings.Run.ObjectSyncTimeOut = 20000 ‘Time in milliseconds

Set Start and End Iteration of DataTable Using Automation Object Model in UFT

If you are having more than one row in the UFT DataTable then you can either run the Test for all rows or for the specified range. The following are the syntaxes for both.
 
The syntax for running a Test for all rows.

The syntax for running a Test for the specified range of rows.

Enable/Disable Smart Identification Using Automation Object Model in UFT

We can enable or disable smart identification using the following syntax.

Set On Error Settings Using Automation Object Model in UFT

To set the on error setting, we can use the following syntax.

Or

Set DataTable Path Using Automation Object Model in UFT

UFT DataTable path is set at the default location using the following syntax.

Add Recovery Scenario Using Automation Object Model in UFT

We can easily add a recovery scenario at runtime using the Automation Object Model (AOM). Use the following syntax

qtApp.Test.Settings.Recovery.SetActivationMode “OnError
qtApp.Test.Settings.Recovery.Add “Path of Recovery scenario file“, “Recovery Scenario Name“, 1
qtApp.Test.Settings.Recovery.Item(1).Enabled = True

Add Multiple Recovery Scenarios Using Automation Object Model in UFT

Capture Image in the Test Result for Failed steps Using Automation Object Model

To capture the images for the failed steps in the test result using the following syntax.

qtApp.Options.Run.ImageCaptureForTestResults = “OnError”
 

Finding All Actions in a Test and Run the Specified one Using AOM

The following code shows how to retrieve all actions inside a Test and runs the required Action. In the following example, only the Action2 of a test script will be executed amongst all actions of a test.

Running a Test and specify it’s test result location Using AOM

Use the following code to run a test and save the result to the specified location.

Create User-Defined Environment Variable at Runtime and Save a Test

Use the following code to create user-defined environment variables at runtime.

After running the test if you will open UFT and go to Test Setting>Environment and select User-Defined variable type, you will see that the above-mentioned environment variables have been added.

User-Defined-Environment-Variable-in-UFT

Get Details of all Associated Function Libraries to a Test Using AOM

Suppose you have a GUI Test and want to retrieve the details of all associated function libraries in the Test. If any of the required libraries are not associated then load it at runtime and continue with the Test flow. The following piece of code can be written inside a Test in UFT.

Get details of associated Object Repositories in a Test Using AOM in UFT

The following piece of code will check whether a specified Object repository is associated with a Test. If it is not associated it will associate it at runtime.

Establishing Connection of UFT with The Quality Center (HP ALM)

We can use the following code to connect UFT with Quality Center.

Load Terminal Emulator add-in and Emulator Options at runtime Using AOM in UFT

If you are working on mainframe automation, the below example illustrates how to select the emulator version and its protocol using the UFT Automation object model (AOM). The following code can be written inside any function library or any Test before starting the execution of automated steps.

The following setting would be done automatically using the above code.TE-Configuration-UFT

Generate Automation Object Model (AOM) Script

You can also generate an AOM script from the Test Setting of a Test. To generate the AOM go to “Run > Settings > Properties Tab > Generate Script” as shown below.
 
Generate AOM UFT
 
The following script would be generated based upon the settings done by you in the Test Settings.

Conclusion

In this tutorial,we have seen many useful exampls of using UFT automation object model.Hope the above examples give you a fair idea of how to use AOM in UFT, please do share this post and like it.

Recommended Posts

Leave a Reply