Professional Documents
Culture Documents
Automation Object Model
Automation Object Model
Automation object model is nothing but collection of objects, methods and properties
which are used to perform quick test 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.
Start
Dim qtApp
Dim qtTest
'Create the QTP Application object
Set qtApp = CreateObject("QuickTest.Application")
'If QTP is not open then open it
If qtApp.launched <> True then
qtApp.Launch
End If
'Make the QuickTest application visible
qtApp.Visible = True
'Set QuickTest run options
'Instruct QuickTest to perform next step when error occurs
qtApp.Options.Run.ImageCaptureForTestResults = "OnError"
qtApp.Options.Run.RunMode = "Fast"
qtApp.Options.Run.ViewResults = False
'Open the test in read-only mode
qtApp.Open "C:\Program Files\HP\QuickTest Professional\Tests\trial", True
'set run settings for the test
Set qtTest = qtApp.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
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 qtApp = CreateObject("QuickTest.Application")
'If QTP is notopen then open it
If qtApp.launched <> True then
qtApp.Launch
End If
'Make the QuickTest application visible
qtApp.Visible = True
'Set QuickTest run options
qtApp.Options.Run.ImageCaptureForTestResults = "OnError"
qtApp.Options.Run.RunMode = "Fast"
qtApp.Options.Run.ViewResults = False
'Open the test in read-only mode
qtApp.Open "C:\Program Files\HP\QuickTest Professional\Tests\trial", True
'set run settings for the test
Set qtTest = qtApp.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
Start
Dim qtApp
Dim qtTest
'Create the QTP Application object
Set qtApp = CreateObject("QuickTest.Application")
'If QTP is notopen then open it
If qtApp.launched <> True then
qtApp.Launch
End If
'Make the QuickTest application visible
qtApp.Visible = True
'Open a new test
qtApp.New
' Release the Application object
Set qtApp = Nothing
Open
Start
QTP, open an existing test, associate Object Repositories and save the
test:
Dim qtApp
Dim qtTest
Dim qtRepositories
'Create the QTP Application object
Set qtApp = CreateObject("QuickTest.Application")
'If QTP is notopen then open it
If qtApp.launched <> True then
qtApp.Launch
End If
'Make the QuickTest application visible
qtApp.Visible = True
qtApp.Open "C:\Program Files\HP\QuickTest Professional\Tests\trial", False
' Get the object repositories collection object of the "SignIn" action
Set qtRepositories = qtApp.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
qtApp.Test.Save
'Close QTP
qtApp.quit
'Release Object
Set qtLibraries = Nothing
Set qtTest = Nothing
Set qtApp = Nothing
Start
QTP, open an existing test, associate libraries and save the test:
Dim qtApp
Dim qtTest
Dim qtLibraries
'Create the QTP Application object
Set qtApp = CreateObject("QuickTest.Application")
'If QTP is notopen then open it
If qtApp.launched <> True then
qtApp.Launch
End If
'Make the QuickTest application visible
qtApp.Visible = True
qtApp.Open "C:\Program Files\HP\QuickTest Professional\Tests\trial", False
'Get the libraries collection object
Set qtLibraries = qtApp.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
qtApp.Test.Save
'Close QTP
qtApp.quit
'Release Object
Set qtLibraries = Nothing
Set qtTest = Nothing ' Release the Test object
Set qtApp = Nothing ' Release the Application object
Start
Dim qtApp
'Create the QTP Application object
Set qtApp = CreateObject("QuickTest.Application")
'If QTP is notopen then open it
If qtApp.launched <> True then
qtApp.Launch
End If
'Make the QuickTest application visible
qtApp.Visible = True
' Open the test
qtApp.Open "C:\Program Files\HP\QuickTest Professional\Tests\trial", False
' Set some environment variables
qtApp.Test.Environment.Value("Root") = "C:\"
qtApp.Test.Environment.Value("Password") = "QuickTest"
qtApp.Test.Environment.Value("Days") = 14
' Save the test
qtApp.Test.Save
'Close QTP
qtApp.quit
'Release Object
Set qtApp = Nothing
Start
Dim qtApp
'Create the QTP Application object
Set qtApp = CreateObject("QuickTest.Application")
'If QTP is notopen then open it
If qtApp.launched <> True then
qtApp.Launch
End If
'Make the QuickTest application visible
qtApp.Visible = True
' Open the test
qtApp.Open "C:\Program Files\HP\QuickTest Professional\Tests\trial", False
' Set some environment variables
qtApp.Test.Environment.Value("Root") = "C:\"
qtApp.Test.Environment.Value("Password") = "QuickTest"
qtApp.Test.Environment.Value("Days") = 14
' Save the test
qtApp.Test.Save
'Close QTP
qtApp.quit
'Release Object
Set qtApp = Nothing
Start
QTP, Open an Existing Test and Get All Available Action Names From the
Test:
Dim qtApp
'Create the QTP Application object
Set qtApp = CreateObject("QuickTest.Application")
'If QTP is notopen then open it
If qtApp.launched <> True then
qtApp.Launch
End If
'Make the QuickTest application visible
qtApp.Visible = True
qtApp.Open "C:\Program Files\HP\QuickTest Professional\Tests\trial", False,
False
'Get count of Action in a test
oActCount=qtApp.Test.Actions.Count
For iCounter=1 to oActCount
' Get the first action in the test by index (start from 1)
MsgBox qtApp.Test.Actions(iCounter).Name
Next
'Close QuickTest
qtApp.Quit
' Release the Application object
Set qtApp = Nothing
Open
Dim qtApp
'Create the QTP Application object
Set qtApp = CreateObject("QuickTest.Application")
13.
14.If qtApp.TDConnection.IsConnected Then ' If connection is successful
15. MsgBox "Succesfully connected to Quality Center"
16.Else
17.
18.End If
19.
20.qtApp.Quit ' Exit QuickTest
21.Set qtApp = Nothing ' Release the Application object
22.'*****************************************************************************
********************
23.'*****************************************************************************
********************
19.
20.qtApp.Open "C:\Tests\Test1", True ' Open the test in read-only mode
21.
22.' set run settings for the test
23.Set qtTest = qtApp.Test
24.
25.qtTest.Settings.Run.IterationMode = "rngIterations" ' Run only iterations 2 to
4
26.qtTest.Settings.Run.StartIteration = 2
27.qtTest.Settings.Run.EndIteration = 4
28.qtTest.Settings.Run.OnError = "NextStep" ' Instruct QuickTest to perform next
step when error occurs
29.
30.Set qtResultsOpt = CreateObject("QuickTest.RunResultsOptions") ' Create the
Run Results Options object
31.qtResultsOpt.ResultsLocation = "C:\Tests\Test1\Res1" ' Set the results location
32.
33.qtTest.Run qtResultsOpt ' Run the test
34.
35.MsgBox qtTest.LastRunResults.Status ' Check the results of the test run
36.qtTest.Close ' Close the test
37.
38.Set qtResultsOpt = Nothing ' Release the Run Results Options object
39.Set qtTest = Nothing ' Release the Test object
40.Set qtApp = Nothing ' Release the Application object
41.'*****************************************************************************
********************
42.'*****************************************************************************
********************
22.End If
23.
24.'Save the test and close QuickTest
25.qtApp.Test.Save ' Save the test
26.qtApp.Quit ' Quit QuickTest
27.
28.Set qtLibraries = Nothing ' Release the test's libraries collection
29.Set qtApp = Nothing ' Release the Application object
30.'*****************************************************************************
********************
31.'*****************************************************************************
********************
4. '*****************************************************************************
********************
5. '*****************************************************************************
********************
6. Dim qtApp
7. Dim qtRepositories
8. Dim lngPosition
9.
10.' Open QuickTest
11.Set qtApp = CreateObject("QuickTest.Application") ' Create the Application ob
ject
12.qtApp.Launch ' Launch QuickTest
13.qtApp.Visible = True ' Set QuickTest to be visible
14.
15.' Open a test and get the "Login" action's object repositories collection
16.qtApp.Open "C:\Tests\Test1", False, False ' Open a test
17.Set qtRepositories = qtApp.Test.Actions("Login").ObjectRepositories ' Get the
object repositories collection object of the "Login" action
18.
19.' Add MainApp.tsr if it's not already in the collection
20.If qtRepositories.Find("C:\MainApp.tsr") = -1 Then ' If the repository cannot be
found in the collection
21.
22.End If
23.
24.'Save the test and close QuickTest
16.qtApp.Test.Environment.Value("Root") = "C:\"
17.qtApp.Test.Environment.Value("Password") = "QuickTest"
18.qtApp.Test.Environment.Value("Days") = 14
19.
20.qtApp.Test.Save ' Save the test
21.
22.qtApp.Quit ' Exit QuickTest
23.Set qtApp = Nothing ' Release the Application object
24.'*****************************************************************************
********************
25.'*****************************************************************************
********************
1. '*****************************************************************************
********************
2. '*****************************************************************************
********************
3. 'Start QTP with specified views
4. '*****************************************************************************
********************
5. '*****************************************************************************
********************
6. Dim qtApp
7. Set qtApp = CreateObject("QuickTest.Application") ' Create the Application ob
ject
8. qtApp.Launch ' Start QuickTest
9.
10.qtApp.ActivateView "ExpertView" ' Display the Expert View
11.qtApp.ShowPaneScreen "ActiveScreen", True ' Display the Active Screen pane
12.qtApp.ShowPaneScreen "DataTable", False ' Hide the Data Table pane
13.qtApp.ShowPaneScreen "DebugViewer", True ' Display the Debug Viewer pane
14.
15.qtApp.WindowState = "Maximized" ' Maximize the QuickTest window
16.qtApp.Visible = True ' Make the QuickTest window visible
17.
18.Set qtApp = Nothing ' Release the Application object
19.'*****************************************************************************
********************
20.'*****************************************************************************
********************