Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 22

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

QTP, open an existing test and Run the Test:

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

' Close the test


qtTest.Close
'Close QTP
qtApp.quit
'Release Object
Set qtTest = Nothing
Set qtApp = 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 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

'Close the test


qtTest.Close
'Close QTP
qtApp.quit
'Release Object
Set qtResultsOpt = nothing
Set qtTest = Nothing
Set qtApp = Nothing

Start

QTP and open New test:

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

QTP and Connect to Quality Center and run QC script:

'Declare the Application object variable


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
If Not qtApp.TDConnection.IsConnected Then
' Make changes in a test on Quality Center with version control

qtApp.TDConnection.Connect "QC URL","DOMAIN Name","Project Name","User


Name","Password",False
'QC URL = QC Server path
'DOMAIN Name = Domain name that contains QC project
'Project Name =Project Name in QC you want to connect to
'Username = Username to connect to Project
'Password = Password to connect to project
'False or True = Whether password is entered in encrypted or normal.
'Value is True for encrypted and FALSE for normal
'Example: qtApp.TDConnection.Connect
'"http://200.168.1.1:8080/qcbin","Default","proj1","qtpworld","qtp",false
End If
'Make Sure about your script path and script name in QC
qtApp.Open "[QualityCenter] Subject\QCScriptPath\ScriptName", False
qtApp.Test.Run
qtApp.TDConnection.Disconnect
'Close QTP
qtApp.quit
'Release Object
Set qtApp = Nothing

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

QTP, Open an Existing Test and Define Environment Variables:

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 with specified views:

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

and minimize QTP Window:

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.WindowState = "Minimized" ' Maximize the QuickTest window
qtApp.WindowState = "Maximized" ' Maximize the QuickTest window
'Release Object
Set qtApp = Nothing

Automation Object Model

Open QTP and Connect to Quality Center


view plainprint?
1. '*****************************************************************************
********************
2. '*****************************************************************************
********************
3. 'Open QTP and Connect to Quality Center
4. '*****************************************************************************
********************
5. '*****************************************************************************
********************
6. Dim qtApp ' Declare the Application object variable
7. Set qtApp = CreateObject("QuickTest.Application") ' Create the Application ob
ject
8. qtApp.Launch ' Start QuickTest
9. qtApp.Visible = True ' Make the QuickTest application visible
10.
11.' Make changes in a test on Quality Center with version control
12.qtApp.TDConnection.Connect "QC URL", "DOMAIN Name", "Project Name", "U
ser Name", "Password", False ' Connect to Quality Center

13.
14.If qtApp.TDConnection.IsConnected Then ' If connection is successful
15. MsgBox "Succesfully connected to Quality Center"
16.Else
17.

MsgBox "Cannot connect to Quality Center"

18.End If
19.
20.qtApp.Quit ' Exit QuickTest
21.Set qtApp = Nothing ' Release the Application object
22.'*****************************************************************************
********************
23.'*****************************************************************************
********************

Start QTP and open New test


view plainprint?
1. '*****************************************************************************
********************
2. '*****************************************************************************
********************
3. 'Start QTP and open New test
4. '*****************************************************************************
********************
5. '*****************************************************************************
********************
6. Dim qtApp ' Declare the application object variable
7. Set qtApp = CreateObject("QuickTest.Application") ' Create the application ob
ject
8.

9. qtApp.Launch ' Start QuickTest


10.qtApp.Visible = True ' Make the QuickTest application visible
11.
12.qtApp.New ' Open a new test
13.
14.Set qtApp = Nothing ' Release the Application object
15.'*****************************************************************************
********************
16.'*****************************************************************************
********************

Start QTP, open an existing test and Run the


Test
view plainprint?
1. '*****************************************************************************
********************
2. '*****************************************************************************
********************
3. 'Start QTP, open an existing test and Run the Test
4. '*****************************************************************************
********************
5. '*****************************************************************************
********************
6. Dim qtApp
7. Dim qtTest
8.
9. Set qtApp = CreateObject("QuickTest.Application") ' Create the Application ob
ject
10.qtApp.Launch ' Start QuickTest

11.qtApp.Visible = True ' Make the QuickTest application visible


12.
13.' Set QuickTest run options
14.qtApp.Options.Run.ImageCaptureForTestResults = "OnError"
15.qtApp.Options.Run.RunMode = "Fast"
16.qtApp.Options.Run.ViewResults = False
17.
18.qtApp.Open "C:\Tests\Test1", True ' Open the test in read-only mode
19.
20.' set run settings for the test
21.Set qtTest = qtApp.Test
22.qtTest.Settings.Run.OnError = "NextStep" ' Instruct QuickTest to perform next
step when error occurs
23.
24.qtTest.Run ' Run the test
25.
26.MsgBox qtTest.LastRunResults.Status ' Check the results of the test run
27.qtTest.Close ' Close the test
28.
29.Set qtTest = Nothing ' Release the Test object
30.Set qtApp = Nothing ' Release the Application object
31.'*****************************************************************************
********************
32.'*****************************************************************************
********************

Start QTP, open an existing test, Run the Test


with configured Run and Result options
view plainprint?
1. '*****************************************************************************
********************
2. '*****************************************************************************
********************
3. 'Start QTP, open an existing test and Run the Test with configured Run option
s
4. ' And Store Run Results in Specified Folder
5. '*****************************************************************************
********************
6. '*****************************************************************************
********************
7. Dim qtApp
8. Dim qtTest
9. Dim qtResultsOpt
10.
11.Set qtApp = CreateObject("QuickTest.Application") ' Create the Application ob
ject
12.qtApp.Launch ' Start QuickTest
13.qtApp.Visible = True ' Make the QuickTest application visible
14.
15.' Set QuickTest run options
16.qtApp.Options.Run.ImageCaptureForTestResults = "OnError"
17.qtApp.Options.Run.RunMode = "Fast"
18.qtApp.Options.Run.ViewResults = False

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.'*****************************************************************************
********************

Start QTP, open an existing test, associate


libraries and save the test
view plainprint?
1. '*****************************************************************************
********************
2. '*****************************************************************************
********************
3. 'Start QTP, open an existing test, associate libraries and save the test
4. '*****************************************************************************
********************
5. '*****************************************************************************
********************
6. Dim qtApp
7. Dim qtLibraries
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 its libraries collection
16.qtApp.Open "C:\Tests\Test1", False, False ' Open a test

17.Set qtLibraries = qtApp.Test.Settings.Resources.Libraries ' Get the libraries co


llection object
18.
19.' Add Utilities.vbs if it's not in the collection
20.If qtLibraries.Find("C:\Utilities.vbs") = -1 Then ' If the library cannot be found i
n the collection
21.

qtLibraries.Add "C:\Utilities.vbs", 1 ' Add the library to the collection

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.'*****************************************************************************
********************

Start QTP, open an existing test, associate


Object Repositories and save the test
view plainprint?
1. '*****************************************************************************
********************
2. '*****************************************************************************
********************
3. 'Start QTP, open an existing test, associate Object Repositories and save the
test

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.

qtRepositories.Add "C:\MainApp.tsr", 1 ' Add the repository to the collection

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 qtRepositories = Nothing ' Release the action's shared repositories collect
ion
29.Set qtApp = Nothing ' Release the Application object
30.'*****************************************************************************
********************
31.'*****************************************************************************
********************

Open and minimize QTP Window


view plainprint?
1. '*****************************************************************************
********************
2. '*****************************************************************************
********************
3. 'Open and minimize QTP Window
4. '*****************************************************************************
********************
5. '*****************************************************************************
********************
6. Dim qtApp
7. Set qtApp = CreateObject("QuickTest.Application") ' Create the Application ob
ject
8. qtApp.Launch ' Start QuickTest
9. qtApp.Visible = True ' Make the QuickTest window visible
10.qtApp.WindowState = "Minimized" ' Maximize the QuickTest window
11.

12.Set qtApp = Nothing ' Release the Application object


13.'*****************************************************************************
********************
14.'*****************************************************************************
********************

Start QTP, Open an Existing Test and Define


Environment Variables
view plainprint?
1. '*****************************************************************************
********************
2. '*****************************************************************************
********************
3. 'Start QTP, Open an Existing Test and Define Environment Variables
4. '*****************************************************************************
********************
5. '*****************************************************************************
********************
6. Dim qtApp
7.
8. Set qtApp = CreateObject("QuickTest.Application") ' Create the Application ob
ject
9. qtApp.Launch ' Start QuickTest
10.qtApp.Visible = True ' Make the QuickTest application visible
11.
12.' Open the test
13.qtApp.Open "C:\Tests\Test1", False ' Open a test named "Test1"
14.
15.' Set some environment variables

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.'*****************************************************************************
********************

Start QTP, Open an Existing Test and Get All


Available Action Names From the Test
view plainprint?
1. '*****************************************************************************
********************
2. '*****************************************************************************
********************
3. 'Start QTP, Open an Existing Test and Get All Available Action Names From the
Test
4. '*****************************************************************************
********************
5. '*****************************************************************************
********************
6. Dim qtApp
7.
8. ' Open QuickTest

9. Set qtApp = CreateObject("QuickTest.Application") ' Create the Application ob


ject
10.qtApp.Launch ' Launch QuickTest
11.qtApp.Visible = True ' Set QuickTest to be visible
12.
13.qtApp.Open "C:\Tests\Test1", False, False ' Open a test
14.
15.oActCount=qtApp.Test.Actions.Count
16.
17.For iCounter=1 to oActCount
18.
19. ' Get the first action in the test by index (start from 1)
20. MsgBox qtApp.Test.Actions(iCounter).Name
21.
22.Next
23.
24.'Close QuickTest
25.qtApp.Quit ' Quit QuickTest
26.
27.Set qtApp = Nothing ' Release the Application object
28.'*****************************************************************************
********************
29.'*****************************************************************************
********************

Start QTP with specified views


view plainprint?

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.'*****************************************************************************
********************

You might also like