Header Ads

How To Work With Automation Object Model In UFT?

AOM stands for Automation Object Model. This is an way to use UFT/QTP  and its resources . By this approach we can control the QTP from a separate program like-a VBS,macro. This is accomplished using  COM interface.that gives a freedom to access the all most 90% of the components of the software. Based on COM , AOM can communicate with the components.(access different methods,properties,object). It provides a set of controls, methods to help a developer/automation tester to execute script without touching UFT. It is externally useful while triggering batchrun from Jenkins or making an one click automation.

What is proper use case

  • This is useful when we want to change the QTP /UFT options during run time
  • Want to control UFT/QTP from our other application
  • Want to do some repetitive task in a regular interval
  • Migrating to continuous integration
  • Want to schedule scripts in a machine.
AOM is the better solution for the above uses. It uses COM (Component Object Model)- In the below section, we will see how to create an object of UFT application and work with different components of it.
There are three popular ways to create object of quick test-
Visual Basic Way:
Dim qtApp as QuickTest.Application
set qtApp=New QuickTest.Application

VBScript way:
Dim qtApp
set qtApp=CreateObject("QuickTest.Application")
Java Script way
var qtApp=new ActiveXObject("QuickTest.Application")
You can choose any one.But in this blog I am going to take Vb scripting:
Basic Settings
Dim qtApp
set qtApp=CreateObject("QuickTest.Application")
qtApp.Launch  ' launch QTP/UFT
qtApp.Activateview "Expertview" 'Open Expert View can be "keyWordView"
qtApp.showPaneScreen "ActiveScreen",True 'show the Active Screen can also be set 
'as "Debugviewer",True or "DataTable" False
qtApp.WindowState="Maximized" 'Maximize the UFT,can aslo be set as "Minimized"

Run Options
qtApp.options.run.RunMode="Fast" can be set to Normal or slow based on the network speed
qtApp.options.run.viewResult=False ' can be true if you want the qtp result to display 
'after a run
qtApp.Test.Settings.Run.DisableSmartIdentification=false 'can be true
Run Settings
This can be achieved in two ways ...

  1. Either you follow the hierarchy
  2. Or create an object of the test module

set qtTest=qtApp.Test
qtTest.settings.run.IterationMode="AllIterations" ' can be rngIterations or rngAll
'to run from iteration x to iteration y
qtTest.settings.run.onError="NextStep" 'can be stopped by passing "Stop"
' or we can show error dialog by passing "Dialog"
Result Settings
Dim qtResultOpt
set qtResultOpt=CreateObject("quickTest.Run ResultsOptions")
qtTest.Run qtResultOpt

if you move all result to a file:
const forReading=1
const forWritting=2
dim fso,f,result
set fso=CreateObject("scripting.FileSystemObject")
set f=fso.openTextfile("c:\test\result.txt",forWritting,True)
'you can create the text file by using fso
set qtResultOpt=CreateObject("quickTest.Run ResultsOptions")
qtTest.Run qtResultOpt
f.write("test1:Name of the test")
'close f,set objects to null if you have no further use
Library Settings
dim qtlibs
'to remove all
Add a library:
If qtLibs.find("path of the lib"\abc.vbs")=-1 then
qtlibs.Add "path of the lib"\abc.vbs",1
End If
qtApp.Test.Save ' in this case you have to open the test in edit mode,readonly false

Repository Settings
set qtRepositories=qtApp.Test.Action("Action Name").ObjectRepositories ' for which the 
'repository needs to be added
If qtRepositories.find("path of the lib"\abc.tsr")=-1 then
qtRepositories.Add "path of the lib"\abc.tsr",1
End If
Environment Variable Settings
Action Settings
qtApp.Test.Actions.Count 'return the actions present in the test
qtApp.Test.Actions("Name of the action like 'Action1'").Description
'returns the description
qtApp.Test.Actions("Name of the action like 'Action1'").Name
'returns the name
'run a particular action by index
qtApp.Test.Actions(index as 1/2).Run
RunAction "Action2",oneIteration 'can be multiple iterations by providing the iteration number
Recovery Settings
'removing all recovery
set qtTestRecovery=qtApp.Test.Settings.Recovery
If qtTestRecovery.count>0 then
End If
'add recovery
qtTestRecovery.Add "path of the recovery file","Name of the recovery",1,"description"

'enabling the recovery:
For intIndex=1 to qtTestRecovery.count
'specify when to activate
Datatable Settings
qtApp.Test.Settings.Resources.DataTablePath="Path of your data table"
Log tracking Settings
 with qtApp.Test.Settings.LogTracking
End With
There are two launcher available out of the box.

  1. Web Application
  2. Window Application

Web launcher Settings
qtApp.Test.Settings.Launcher("Web").Activate=true 'can be false
qtApp.Test.Settings.Browser="IE", Can be chrome,firefox if supports

Windows Application launcher Settings
qtApp.Test.Settings.Launcher("Window Application").Activate=true 'can be false
qtApp.Test.Settings.Applications.RemoveAll 'removes all pre loaded Applications
qtApp.Test.Settings.RecordOnQTDescendant="False" 'record settings

Addins Settings
arrAddins=qtApp.GetAssociatedAddinsForTest("Test path and Test Name")
'check if loading is successful
For Each testAddin in arrAddins
If (qtApp.Addins(testAddin)).status <> "Active" then
Exit for
End if
'if change in the loaded addins is necessary
If blnAddinRequired Then
Dim blnActivateOk
blnActivateOk=qtApp.SetActiveAddins(arrAddins,error description)
If Not blnActivateOk Then
End if
End if 
Set Parameters
To work with these, we need to create these parameters in QTP first.
Set pDefcoll=qtApp.Test.ParameterDefination
Set qtpParam=pDefcoll.GetParameters()
on Error Resume Next
How to save Test
If qtApp.Test.IsNew Then
qtApp.Test.SaveAs "path of the script and Script Name"
End If
How to Connect To ALM/QC
qtApp.TDConnections.Connect "QCURL","Domain","Project Name","UserName","Password",false
How to Run a Test from ALM/QC
qtApp.TDConnections.Connect "QCURL","Domain","Project Name","UserName","Password",false
If qtApp.TDConnection.IsConnected Then
qtApp.Open [QualityCentre]Subject\path\script Name,False
How to Log a bug in ALM/QC
Here is complete guide of the code: http://www.ufthelp.com/2014/09/how-to-log-bug-in-alm-using-ota.html Here is a small different way to do:
Dim qcApp
 Dim BugFact,NewBug
 Set qcApp = CreateObject("TDApiOle80.TDConnection")
 'Intilizing the QC connection
 qcApp.InitConnectionEx "https://alm.com/qcbin"
 'Verifying User is connected
 If qcApp.Connected Then
  Print "User Connected to ALM Server"
  Print "User is not Connected to ALM Server"
  Exit Function 
 End If
 'Filling the UserName and Password for ALM
 qcApp.Login sUName,sPwd
 'Verifying User is Logged into ALM
 If qcApp.LoggedIn Then
  Print "User is Logged into ALM Server"
  Print "User is not Logged into ALM Server"
  Exit Function 
 End If
 'Connects user to specified Domain and Project
 qcApp.Connect sDomain,sProject
Set BugFactory=qcApp.BugFactory
Set Bug=BugFactory.AddItem(Nothing)
Bug.Summary="Test Bug"
Bug.AssignedTo="Dev Team"
Easy Way to Build this AOM file: Setup everything in UFT/QTP:
Option 1: Go to test settings->General Tab-->Object Identification Tab-->Click on Generate button-->Provide the path-->Provide the name-->Click on save
Option 2: Go to Test-->Settings-->Properties Tab-->Click on Generate button-->Provide the path-->Provide the name-->Click on save
Option-3:Go to tools->Option-->General Tab-->Click on Generate button-->Provide the path-->Provide the name-->Click on save
after few settings you will be able to understand the settings.
Powered by Blogger.