An object model is a collection of classes or objects which can controlled by any program. An object model gives a facility to control the functionality of an application programmatically.
The UFT Automation Object Model (AOM) is a set of its classes and interfaces together with their properties, methods and events and their relationships.
Using AOM the functionalities of UFT can be controlled from any other applications/programs by using a scripting or programming language.
The functionalities that can be controlled are listed below but not limited to –
- Loads all the required add-ins for a test
- Makes QTP visible while execution
- Opens the Test using the specified location
- Associates Function Libraries
- Specifies the Common Object Sync Time out
- Start and End Iteration
- Enable/Disable Smart Identification
- On Error Settings
- Data Table Path
- Recovery Scenario Settings
- Log Tracking Settings
To create the automation object, we use “CreateObject” function. Once the object has been created, we can access all other objects, methods and properties of the UFT. CreateObject creates and returns the reference to an automation object.
Syntax: CreateObject (Servername.typename [, location])
Below is the example in VBScript for creating the UFT application object and starting UFT in visible mode.
Dim qtApp
Dim qtTest
Set qtApp = CreateObject(“QuickTest.Application”)
If qtApp.launched <> True then
qtApp.Launch
End If
qtApp.Visible = True
we need to set the various parameters for execution of the test case
qtApp.Options.Run.ImageCaptureForTestResults = “OnError”
qtApp.Options.Run.RunMode = “Fast”
qtApp.Options.Run.ViewResults = False
Now we are opening the test, the test can be opened in two mode, read only or edit mode. Here, we have mentioned the flag as true which opens the test in the read only mode. After opening the code, we create the object for the execution and instructs UFT what needs to be done in case of error. And finally run the test using .Run method
qtApp.Open “C:\Program Files\HP\QuickTest Professional\Tests\Demo”, True
Set qtTest = qtApp.Test
qtTest.Settings.Run.OnError = “NextStep”
qtTest.Run
After the execution, we have to close the test first and then close the QTP using .quit method. In the end we need to release the object using Set Objectname=nothing.
qtTest.Close
qtApp.quit
Set qtTest = Nothing
Set qtApp = Nothing
Generating Automation Scripts
The UFT provides an easy option to generate automation scripts for few settings.
- Test Setting dialog box (File > Setting )
- Options dialog box (Tools > Options > GUI Testing)
- Object identification dialog box (Tools > Object Identification)
These dialog boxes contain a generate script button which generates an automation script file (.vbs) by just clicking on it as shown below (from test setting File > setting). This file contains the current settings from the corresponding dialog box.
A Sample Code looks like this –
Dim App ‘As Application
Set App = CreateObject(“QuickTest.Application”)
App.Launch
App.Visible = True
App.Test.Settings.Launchers(“Web”).Active = True
App.Test.Settings.Launchers(“Web”).Browser = “IE”
App.Test.Settings.Launchers(“Web”).Address = “www.google.com”
App.Test.Settings.Launchers(“Web”).CloseOnExit = False
App.Test.Settings.Launchers(“Windows Applications”).Active = False
App.Test.Settings.Launchers(“Windows Applications”).Applications.RemoveAll
App.Test.Settings.Launchers(“Windows Applications”).RecordOnQTDescendants = True
App.Test.Settings.Launchers(“Windows Applications”).RecordOnExplorerDescendants = False
App.Test.Settings.Launchers(“Windows Applications”).RecordOnSpecifiedApplications = True
App.Test.Settings.Run.IterationMode = “rngAll”
App.Test.Settings.Run.StartIteration = 1
App.Test.Settings.Run.EndIteration = 1
App.Test.Settings.Run.ObjectSyncTimeOut = 20000
App.Test.Settings.Run.DisableSmartIdentification = False
App.Test.Settings.Run.OnError = “Dialog”
App.Test.Settings.Resources.DataTablePath = “<Default>”
App.Test.Settings.Resources.Libraries.RemoveAll
App.Test.Settings.Web.BrowserNavigationTimeout = 60000
App.Test.Settings.Web.ActiveScreenAccess.UserName = “”
App.Test.Settings.Web.ActiveScreenAccess.Password = “”
”””””””””””””””””””””””””””””””””””””
‘ System Local Monitoring settings
”””””””””””””””””””””””””””””””””””””
App.Test.Settings.LocalSystemMonitor.Enable = false
”””””””””””””””””””””””””””””””””””””
‘ Log Tracking settings
”””””””””””””””””””””””””””””””””””””
With App.Test.Settings.LogTracking
.IncludeInResults = False
.Port = 18081
.IP = “127.0.0.1”
.MinTriggerLevel = “ERROR”
.EnableAutoConfig = False
.RecoverConfigAfterRun = False
.ConfigFile = “”
.MinConfigLevel = “WARN”
End With
Leave a Reply Cancel reply