Automation Object Model
Automation object model is nothing but collection of objects,
methods and properties which are used to perform quicktest operations.
Throughout this object model we can perform any operation described in QTP
interface. For every option in QTP menus (Interface) have Objects, methods and
properties are there in this model.
AOM is the concept to automate QTP itself.
-----------------------------------------------------------------------------------------------------------------------
Automatically
Start QTP, open an existing test and Run
the Test:
Dim App
Dim qtTest
'Create the
QTP Application object
Set App =
CreateObject("QuickTest.Application")
'If QTP is
notopen then open it
If App.launched <> True then
App.Launch
End If
'Make the
QuickTest application visible
App.Visible
= True
'Set
QuickTest run options
'Instruct
QuickTest to perform next step when error occurs
App.Options.Run.ImageCaptureForTestResults
= "OnError"
App.Options.Run.RunMode
= "Fast"
App.Options.Run.ViewResults
= False
'Open the
test in read-only mode
App.Open
"C:\Program Files\HP\QuickTest Professional\Tests\trial", True
'set run
settings for the test
Set qtTest =
App.Test
'Instruct
QuickTest to perform next step when error occurs
qtTest.Settings.Run.OnError
= "NextStep"
'Run the
test
qtTest.Run
'Check the
results of the test run
MsgBox
qtTest.LastRunResults.Status
' Close the
test
qtTest.Close
'Close QTP
App.quit
'Release
Object
Set qtTest =
Nothing
Set App =
Nothing
Start QTP, open an existing test and Run the
Test And Store Run Results in Specified
Folder:
Dim qtApp
Dim qtTest
Dim
qtResultsOpt
'Create the
QTP Application object
Set App =
CreateObject("QuickTest.Application")
'If QTP is
notopen then open it
If App.launched <> True then
App.Launch
End If
'Make the
QuickTest application visible
App.Visible
= True
'Set
QuickTest run options
App.Options.Run.ImageCaptureForTestResults
= "OnError"
App.Options.Run.RunMode
= "Fast"
App.Options.Run.ViewResults
= False
'Open the
test in read-only mode
App.Open
"C:\Program Files\HP\QuickTest Professional\Tests\trial", True
'set run
settings for the test
Set qtTest =
App.Test
'Instruct
QuickTest to perform next step when error occurs
qtTest.Settings.Run.OnError
= "NextStep"
'Create the
Run Results Options object
Set
qtResultsOpt = CreateObject("QuickTest.RunResultsOptions")
'Set the
results location
qtResultsOpt.ResultsLocation
= "D:\Result"
' Run the
test
qtTest.Run
qtResultsOpt
'Check the
results of the test run
MsgBox
qtTest.LastRunResults.Status
'Close the
test
qtTest.Close
'Close QTP
App.quit
'Release
Object
Set
qtResultsOpt = nothing
Set qtTest =
Nothing
Set App =
Nothing
Start QTP and open New
test:
Dim App
Dim qtTest
'Create the
QTP Application object
Set App =
CreateObject("QuickTest.Application")
'If QTP is
notopen then open it
If App.launched <> True then
App.Launch
End If
'Make the
QuickTest application visible
App.Visible
= True
' Open a new
test
App.New
Set App =
Nothing ' Release the Application object
Start QTP, open an
existing test, associate Object Repositories and save the test:
Dim App
Dim qtTest
Dim
qtRepositories
'Create the
QTP Application object
Set App =
CreateObject("QuickTest.Application")
'If QTP is
notopen then open it
If App.launched <> True then
App.Launch
End If
'Make the
QuickTest application visible
App.Visible
= True
App.Open
"C:\Program Files\HP\QuickTest Professional\Tests\trial", False
' Get the
object repositories collection object of the "SignIn" action
Set
qtRepositories = App.Test.Actions("SignIn").ObjectRepositories
' Add Object repositry "Reposit.tsr" if
it's not already associated wit action "SignIn"
If
qtRepositories.Find("D:\Reposit.tsr") = -1 Then
qtRepositories.Add
"D:\Reposit.tsr", 1
End If
'Save the
test
App.Test.Save
'Close QTP
App.quit
'Release
Object
Set
qtLibraries = Nothing
Set qtTest =
Nothing
Set App =
Nothing
-----------------------------------------------------------------------------------------------------------------------
Start QTP, open an
existing test, associate libraries and save the test:
Dim App
Dim qtTest
Dim
qtLibraries
'Create the
QTP Application object
Set App =
CreateObject("QuickTest.Application")
'If QTP is
notopen then open it
If App.launched <> True then
App.Launch
End If
'Make the
QuickTest application visible
App.Visible
= True
App.Open
"C:\Program Files\HP\QuickTest Professional\Tests\trial", False
'Get the
libraries collection object
Set
qtLibraries = App.Test.Settings.Resources.Libraries
'If the
library file "libraary.vbs" is not assiciates with the Test then
associate it
If
qtLibraries.Find("D:\libraary.vbs") = -1 Then
qtLibraries.Add "D:\libraary.vbs",
1
End If
'Save the
test
App.Test.Save
'Close QTP
App.quit
'Release
Object
Set
qtLibraries = Nothing
Set qtTest =
Nothing ' Release the Test object
Set App =
Nothing ' Release the Application object
Generating script for QTP
Settings and QTP Options for AOM
Defining
Settings in QTP
To know, how
settings are defined and QTP object is launched, and settings are defined using
AOM, Go to File>Settings>Properties and click on Generate Script. This
will generate a script with all the default setting parameters
The Content
of the script will be as follows:
Dim App 'As
Application
Set App =
CreateObject("QuickTest.Application")
App.Launch
App.Visible
= True
App.Test.Settings.Launchers("Web").Active
= False
App.Test.Settings.Launchers("Web").Browser
= "IE"
App.Test.Settings.Launchers("Web").Address
= "http://www.rediff.com"
App.Test.Settings.Launchers("Web").CloseOnExit
= True
App.Test.Settings.Launchers("Windows
Applications").Active = True
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
= ""
Defining Options in QTP
To know the
current options settings in QTP, we can generate a script similar to Settings
as defined above through Tools>Options>General and clicking on generate
scripts.
Dim App 'As
Application
Set App =
CreateObject("QuickTest.Application")
App.Launch
App.Visible
= True
App.Options.DisableVORecognition
= False
App.Options.AutoGenerateWith
= False
App.Options.WithGenerationLevel
= 2
App.Options.TimeToActivateWinAfterPoint
= 500
App.Options.SaveLoadAndMonitorData
= True
App.Options.Run.RunMode
= "Fast"
App.Options.Run.ViewResults
= True
App.Options.Run.StepExecutionDelay
= 0
App.Options.Run.MovieCaptureForTestResults
= "Never"
App.Options.Web.AddToPageLoadTime
= 10
App.Options.Web.RecordCoordinates
= False
App.Options.Web.RecordMouseDownAndUpAsClick
= False
App.Options.Web.RecordAllNavigations
= False
App.Options.Web.RecordByWinMouseEvents
= ""
App.Options.Web.BrowserCleanup
= False
App.Options.Web.RunOnlyClick
= False
App.Options.Web.RunMouseByEvents
= True
App.Options.Web.RunUsingSourceIndex
= True
App.Options.Web.EnableBrowserResize
= True
App.Options.Web.PageCreationMode
= "URL"
App.Options.Web.CreatePageUsingUserData
= "Get Post"
App.Options.Web.CreatePageUsingNonUserData
= ""
App.Options.Web.CreatePageUsingAdditionalInfo
= True
App.Options.Web.FrameCreationMode
= "URL"
App.Options.Web.CreateFrameUsingUserData
= "Get Post"
App.Options.Web.CreateFrameUsingNonUserData
= ""
App.Options.Web.CreateFrameUsingAdditionalInfo
= True
App.Options.WindowsApps.AttachedTextRadius
= 35
App.Options.WindowsApps.AttachedTextArea
= "TopLeft"
App.Options.WindowsApps.ExpandMenuToRetrieveProperties
= True
App.Options.WindowsApps.NonUniqueListItemRecordMode
= "ByName"
App.Options.WindowsApps.RecordOwnerDrawnButtonAs
= "PushButtons"
App.Options.WindowsApps.ForceEnumChildWindows
= 0
App.Options.WindowsApps.ClickEditBeforeSetText
= 0
App.Options.WindowsApps.VerifyMenuInitEvent
= 0
App.Options.TextRecognitionOrder
= "APIThenOCR"
App.Folders.RemoveAll
No comments:
Post a Comment