Ad Home

Theme images by kelvinjay. Powered by Blogger.

Travel

Header Ads

Java

Selenium

UFT

Framework

General QA Concept

BDD

» » » » » » » » » » 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"
qtApp.Test.Settings.web.BrowserNavigationTimeOut=50000
qtApp.Test.Settings.web.ActiveScreenAccess.userName="myUserName"
qtApp.Test.Settings.web.ActiveScreenAccess.password="password"

Run Options
qtApp.options.run.ImageCaptureForTestResult="onError"
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.ObjectSyncTimeOut=100000
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.startIteration=1
qtTest.settings.run.EndIteration=3
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")
qtResultOpt.ResultLocation="C:\testpath\Result\"
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")
qtResultOpt.ResultLocation="C:\testpath\Result\"
qtTest.Run qtResultOpt
result=qtTest.LastRunresults.Status
f.write("test1:Name of the test")
f.write(result)
f.writeBlankLines(1)
'close f,set objects to null if you have no further use
Library Settings
dim qtlibs
qtlibs=qtApp.Test.Settings.Resolurces.libraries
'to remove all
qtLibs.removeAll
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
qtApp.Test.Environment.value("userName")="myUserName"
qtApp.Test.Environment.value("password")="password"
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
or
setqtTest=qtApp.Test.Action(index)
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
qtTestRecovery.RemoveAll
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
qtTestRecovery.item(intIndex).Enabled=True
Next
or
qtTestRecovery.Enabled=true
'specify when to activate
qtTestRecovery.setActivationMode="onError"
Datatable Settings
qtApp.Test.Settings.Resources.DataTablePath="Path of your data table"
Log tracking Settings
 with qtApp.Test.Settings.LogTracking
.Includeinresult=False
.port=18081
.IP="127.0.0.1"
.MinTriggerLevel="Error"
.EnableAutoConfig=False
.RecoverConfigAfterRun=False
.configFile=""
.MinConfigLevel="Warn"
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
qtApp.Test.Settings.Address="www.google.com"
qtApp.Test.Settings.CloseOnExit=true

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
qtApp.Test.Settings.RecordOnSpecifiedApplications=True


Addins Settings
arrAddins=qtApp.GetAssociatedAddinsForTest("Test path and Test Name")
'check if loading is successful
blnAddinRequired=False
For Each testAddin in arrAddins
If (qtApp.Addins(testAddin)).status <> "Active" then
blnAddinRequired=True
Exit for
End if
Next
'if change in the loaded addins is necessary
If blnAddinRequired Then
Dim blnActivateOk
blnActivateOk=qtApp.SetActiveAddins(arrAddins,error description)
If Not blnActivateOk Then
WScript.quit
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
qtpParam.Item("UserName").value="myUserName"
qtpParam.Item("Password").value="myPassword"
How to save Test
If qtApp.Test.IsNew Then
qtApp.Test.SaveAs "path of the script and Script Name"
Else
qtApp.Test.Save
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
qtApp.Test.Run
qtApp.TDConnections.Disconnect
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"
 Else
  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"
 Else
  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.Status="New"
Bug.Summary="Test Bug"
Bug.Priority="3-Medium"
Bug.AssignedTo="Dev Team"
Bug.DetectedBy=myUserName
Bug.Post
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.

«
Next
Newer Post
»
Previous
Older Post

No comments:

Leave a Reply