QTP -18 QTP Automation Object Model

18 QTP Automation Object Model

Concept: QTP provides a COM interface which allowsautomation QTP itself. E.g. launch QTP, configure QTP, run a script etc

18.1 Object Model (ref “QuickTest Project” in QTP Manual Help)

Application:

--Test

--Options

--TDConnection

--Folders

--Addins

--BusinessComponent(Test)

--UI

 

18.2How can we use AOM to run a QTP test case?

 e.g. Sample code isas following:

Dim qtApp  Set qtApp = CreateObject("QuickTest.Application")

 qtApp.Launch ' Start QuickTest

 qtApp.Visible = True

 qtApp.Open "C:\Tests\Test1", True

 qtApp.Test.Run

 Set qtApp = NothingDim qtApp Dim qtApp Dim qtApp Dim qtApp Dim qtApp Dim qtApp Dim qtApp Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Dim qtStdLauncher 'As QuickTest.StdLauncher ' Declare an Windows Applications launcher variable
Dim qtStdApp 'As QuickTest.StdApplication ' Declare as StdApplication object variable
Dim strAdded ' Declare a string variable for the added applications

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

' Preparare application and test
qtApp.SetActiveAddins Array() ' Remove all add-ins from the collection so that QuickTest opens with no add-ins loaded
qtApp.Launch ' Start QuickTest
qtApp.Visible = True' Make the QuickTest application visible
qtApp.Test.SetAssociatedAddins Array() ' Remove all add-ins from the test's associated add-ins list.
Set qtStdLauncher = qtApp.Test.Settings.Launchers.Item("Windows Applications") ' Return the Windows Applications launcher

qtStdLauncher.Active = True' Instruct QuickTest to open applications when the record session begins

' Set the applications under test
qtStdLauncher.Applications.AddApplication "C:\Viewer.exe", "C:\"' Add an application
qtStdLauncher.Applications.AddApplication "D:\Apps\Editor.exe", "D:\Apps"' Add another application

' Save changes and clean up
qtApp.Test.SaveAs "C:\Tests\NewTest"' Save the test
qtApp.Quit ' Exit QuickTest
Set qtStdLauncher = Nothing' Release the Windows Applications launcher object
Set qtApp = Nothing' Release the Application object

Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Dim qtStdLauncher 'As QuickTest.StdLauncher ' Declare an Windows Applications launcher variable
Dim qtStdApp 'As QuickTest.StdApplication ' Declare as StdApplication object variable
Dim strAdded ' Declare a string variable for the added applications

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

' Preparare application and test
qtApp.SetActiveAddins Array() ' Remove all add-ins from the collection so that QuickTest opens with no add-ins loaded
qtApp.Launch ' Start QuickTest
qtApp.Visible = True' Make the QuickTest application visible
qtApp.Test.SetAssociatedAddins Array() ' Remove all add-ins from the test's associated add-ins list.
Set qtStdLauncher = qtApp.Test.Settings.Launchers.Item("Windows Applications") ' Return the Windows Applications launcher

qtStdLauncher.Active = True' Instruct QuickTest to open applications when the record session begins

' Set the applications under test
qtStdLauncher.Applications.AddApplication "C:\Viewer.exe", "C:\"' Add an application
qtStdLauncher.Applications.AddApplication "D:\Apps\Editor.exe", "D:\Apps"' Add another application

' Save changes and clean up
qtApp.Test.SaveAs "C:\Tests\NewTest"' Save the test
qtApp.Quit ' Exit QuickTest
Set qtStdLauncher = Nothing' Release the Windows Applications launcher object
Set qtApp = Nothing' Release the Application object

Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Dim qtStdLauncher 'As QuickTest.StdLauncher ' Declare an Windows Applications launcher variable
Dim qtStdApp 'As QuickTest.StdApplication ' Declare as StdApplication object variable
Dim strAdded ' Declare a string variable for the added applications

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

' Preparare application and test
qtApp.SetActiveAddins Array() ' Remove all add-ins from the collection so that QuickTest opens with no add-ins loaded
qtApp.Launch ' Start QuickTest
qtApp.Visible = True' Make the QuickTest application visible
qtApp.Test.SetAssociatedAddins Array() ' Remove all add-ins from the test's associated add-ins list.
Set qtStdLauncher = qtApp.Test.Settings.Launchers.Item("Windows Applications") ' Return the Windows Applications launcher

qtStdLauncher.Active = True' Instruct QuickTest to open applications when the record session begins

' Set the applications under test
qtStdLauncher.Applications.AddApplication "C:\Viewer.exe", "C:\"' Add an application
qtStdLauncher.Applications.AddApplication "D:\Apps\Editor.exe", "D:\Apps"' Add another application

' Save changes and clean up
qtApp.Test.SaveAs "C:\Tests\NewTest"' Save the test
qtApp.Quit ' Exit QuickTest
Set qtStdLauncher = Nothing' Release the Windows Applications launcher object
Set qtApp = Nothing' Release the Application object

 

18.3How to use AOM to change the starting and ending iteration?

 

 

 

' set run settings for the test

Set qtTest = qtApp.Test

qtTest.Settings.Run.IterationMode = "rngIterations" ' Run iterations 2 to 4

qtTest.Settings.Run.StartIteration = 2

qtTest.Settings.Run.EndIteration = 4

qtTest.Settings.Run.OnError = "NextStep" ' run next step when error occursDim qtApp Dim qtApp Dim qtApp Dim qtApp Dim qtApp Dim qtApp Dim qtApp Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Dim qtStdLauncher 'As QuickTest.StdLauncher ' Declare an Windows Applications launcher variable
Dim qtStdApp 'As QuickTest.StdApplication ' Declare as StdApplication object variable
Dim strAdded ' Declare a string variable for the added applications

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

' Preparare application and test
qtApp.SetActiveAddins Array() ' Remove all add-ins from the collection so that QuickTest opens with no add-ins loaded
qtApp.Launch ' Start QuickTest
qtApp.Visible = True' Make the QuickTest application visible
qtApp.Test.SetAssociatedAddins Array() ' Remove all add-ins from the test's associated add-ins list.
Set qtStdLauncher = qtApp.Test.Settings.Launchers.Item("Windows Applications") ' Return the Windows Applications launcher

qtStdLauncher.Active = True' Instruct QuickTest to open applications when the record session begins

' Set the applications under test
qtStdLauncher.Applications.AddApplication "C:\Viewer.exe", "C:\"' Add an application
qtStdLauncher.Applications.AddApplication "D:\Apps\Editor.exe", "D:\Apps"' Add another application

' Save changes and clean up
qtApp.Test.SaveAs "C:\Tests\NewTest"' Save the test
qtApp.Quit ' Exit QuickTest
Set qtStdLauncher = Nothing' Release the Windows Applications launcher object
Set qtApp = Nothing' Release the Application object

Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Dim qtStdLauncher 'As QuickTest.StdLauncher ' Declare an Windows Applications launcher variable
Dim qtStdApp 'As QuickTest.StdApplication ' Declare as StdApplication object variable
Dim strAdded ' Declare a string variable for the added applications

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

' Preparare application and test
qtApp.SetActiveAddins Array() ' Remove all add-ins from the collection so that QuickTest opens with no add-ins loaded
qtApp.Launch ' Start QuickTest
qtApp.Visible = True' Make the QuickTest application visible
qtApp.Test.SetAssociatedAddins Array() ' Remove all add-ins from the test's associated add-ins list.
Set qtStdLauncher = qtApp.Test.Settings.Launchers.Item("Windows Applications") ' Return the Windows Applications launcher

qtStdLauncher.Active = True' Instruct QuickTest to open applications when the record session begins

' Set the applications under test
qtStdLauncher.Applications.AddApplication "C:\Viewer.exe", "C:\"' Add an application
qtStdLauncher.Applications.AddApplication "D:\Apps\Editor.exe", "D:\Apps"' Add another application

' Save changes and clean up
qtApp.Test.SaveAs "C:\Tests\NewTest"' Save the test
qtApp.Quit ' Exit QuickTest
Set qtStdLauncher = Nothing' Release the Windows Applications launcher object
Set qtApp = Nothing' Release the Application object

Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Dim qtStdLauncher 'As QuickTest.StdLauncher ' Declare an Windows Applications launcher variable
Dim qtStdApp 'As QuickTest.StdApplication ' Declare as StdApplication object variable
Dim strAdded ' Declare a string variable for the added applications

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

' Preparare application and test
qtApp.SetActiveAddins Array() ' Remove all add-ins from the collection so that QuickTest opens with no add-ins loaded
qtApp.Launch ' Start QuickTest
qtApp.Visible = True' Make the QuickTest application visible
qtApp.Test.SetAssociatedAddins Array() ' Remove all add-ins from the test's associated add-ins list.
Set qtStdLauncher = qtApp.Test.Settings.Launchers.Item("Windows Applications") ' Return the Windows Applications launcher

qtStdLauncher.Active = True' Instruct QuickTest to open applications when the record session begins

' Set the applications under test
qtStdLauncher.Applications.AddApplication "C:\Viewer.exe", "C:\"' Add an application
qtStdLauncher.Applications.AddApplication "D:\Apps\Editor.exe", "D:\Apps"' Add another application

' Save changes and clean up
qtApp.Test.SaveAs "C:\Tests\NewTest"' Save the test
qtApp.Quit ' Exit QuickTest
Set qtStdLauncher = Nothing' Release the Windows Applications launcher object
Set qtApp = Nothing' Release the Application object

 

18.4How to use AOM to launch QTP on a remote machine

Const remoteMachineIP = "127.2.3.4"

Set qtApp = CreateObject("QuickTest.Application", remoteMachineIP)

Note: the remote machine has set QTP to “Allow other mercuryproducts…” model.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值