QuickTest Automation Object Model
The way QTP is used to automate different applications, we can even automate QTP itself. For automating QTP, first of all one need to create a object of QuickTest Application and then by using this object, one can easily do all the configuration and run settings that is provided with the QTP interface.
QuickTest Automation Object Model consists of objects, methods and properties. In QuickTest AOM, there is a automation object for most of the dialog boxes in QuickTest. Similarly by using corresponding object properties, most options in dialog boxes can be set or retrieved. Also most menu commands and other operations have corresponding automation methods.
Example-
'This example open a test, do the configuration and run setting, run the test
Dim qtApp 'As
QuickTest.Application ' Declare the Application object variable
Dim qtTest 'As QuickTest.Test ' Declare
a Test object variable
Dim qtResultsOpt
'As QuickTest.RunResultsOptions ' Declare a Run Results
Options object variable
'Create the Application object
Set qtApp =
CreateObject("QuickTest.Application")
qtApp.Launch ' Start QuickTest
qtApp.Visible = True ' Make the QuickTest application
visible
'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:\Tests\Test1", True
'Set run settings for the test
Set qtTest =
qtApp.Test
qtTest.Settings.Run.IterationMode = "rngIterations" ' Run only iterations 2
to 4
qtTest.Settings.Run.StartIteration =
2
qtTest.Settings.Run.EndIteration = 4
qtTest.Settings.Run.OnError = "NextStep" ' Instruct QuickTest to
perform next step when error occurs
'Adding Libraries-
qtApp.Test.Settings.Resources.Libraries.RemoveAll
qtApp.Test.Settings.Resources.Libraries.Add objectFunctionFilePath
qtApp.Test.Settings.Resources.Libraries.Add globalFunctionFilePath
'Adding Environment Variable
qtApp.Test.Environment.Value("User_ID") = userid
'Adding Recovery Scenarios
'create a recovery object
Set qtTestRecovery = qtApp.Test.Settings.Recovery ' Return the Recovery object
If qtTestRecovery.Count > 0 Then ' If there are any default scenarios specified for the test
qtTestRecovery.RemoveAll ' Remove them
End If
'Add recovery scenarios
qtTestRecovery.Add recoveryPath, "objectNotFound", 1 ' Add the "objectNotFound" scenario
'Enable all scenarios
For intIndex = 1 To qtTestRecovery.Count ' Iterate the scenarios
qtTestRecovery.Item(intIndex).Enabled = True ' Enable each Recovery Scenario
Next
'Enable the recovery mechanism (with default, on errors, setting)
qtTestRecovery.Enabled = True
'Ensure that the recovery mechanism is set to be activated only after errors
qtTestRecovery.SetActivationMode "OnError"
'Create the Run Results Options object
Set
qtResultsOpt = CreateObject("QuickTest.RunResultsOptions")
qtResultsOpt.ResultsLocation = "C:\Tests\Test1\Res1" ' Set the results
location
' Run the test
qtTest.Run qtResultsOpt
ResultStatus=qtTest.LastRunResults.Status 'Check the results of the test run"
'Save the test and close QuickTest
qtApp.Test.Save
' Save the test
qtTest.Close ' Close the
test
qtApp.Quit ' Quit QuickTest
'Release the objects
Set qtResultsOpt = Nothing
Set qtTest = Nothing
Set qtApp = Nothing
Dim qtApp 'As
QuickTest.Application ' Declare the Application object variable
'Set QuickTest run
options
qtApp.Test.Settings.Resources.Libraries.RemoveAll qtApp.Test.Settings.Resources.Libraries.Add objectFunctionFilePath qtApp.Test.Settings.Resources.Libraries.Add globalFunctionFilePath 'Adding Environment Variable qtApp.Test.Environment.Value("User_ID") = userid 'Adding Recovery Scenarios Set qtTestRecovery = qtApp.Test.Settings.Recovery ' Return the Recovery object If qtTestRecovery.Count > 0 Then ' If there are any default scenarios specified for the test qtTestRecovery.RemoveAll ' Remove them End If 'Add recovery scenarios qtTestRecovery.Add recoveryPath, "objectNotFound", 1 ' Add the "objectNotFound" scenario 'Enable all scenarios For intIndex = 1 To qtTestRecovery.Count ' Iterate the scenarios qtTestRecovery.Item(intIndex).Enabled = True ' Enable each Recovery Scenario Next 'Enable the recovery mechanism (with default, on errors, setting) qtTestRecovery.Enabled = True 'Ensure that the recovery mechanism is set to be activated only after errors qtTestRecovery.SetActivationMode "OnError"
'Create the Run Results Options object ResultStatus=qtTest.LastRunResults.Status 'Check the results of the test run"
qtApp.Test.Save
' Save the test |
No comments:
Post a Comment