Wednesday 13 June 2012

Automation Object Model

SOURECE QTP HELP FILE

We can use QTP Automation Object Model (AOM) to write scripts that automate QTP operations .The Quick Test AOM provides objects, methods, and properties that we can use to control Quick Test from other application .

*Here is the example how we can create the QuickTest application object and automate some basic operations of QTP :-

Dim qtApp=CreateObject(“QuickTest.Application”)   ‘ Create the application Object
qtApp.Launch  ‘ Start Quick Test
qtApp.Visible=True   ‘ Make it visible
qtApp.Options.DisableVORecognition = False
qtApp.Options.AutoGenerateWith = False
qtApp.Options.WithGenerationLevel = 2
qtApp.Quit

We can also create the object for Action,Action Parameter, Addin ,DataTable,Object Repositories etc. and successfully automate their operation from outside the QTP .

*Here is the example that opens QTP Test with associated addins:-

Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Dim blnNeedChangeAddins ' Declare a flag for indicating whether the test's associated add-ins are currently loaded
Dim arrTestAddins ' Declare the variable for storing the test's associated add-ins

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

arrTestAddins = qtApp.GetAssociatedAddinsForTest("C:\Tests\Test1") ' Create an array containing the list of addins associated with this test

' Check if all required add-ins are all already loaded
blnNeedChangeAddins = False ' Assume no change is necessary
For Each testAddin In arrTestAddins ' Iterate over the test's associated add-ins list
    If qtApp.Addins(testAddin).Status <> "Active" Then ' If an associated add-in is not loaded
        blnNeedChangeAddins = True ' Indicate that a change in the loaded add-ins is necessary
        Exit For ' Exit the loop
    End If
Next

If qtApp.Launched And blnNeedChangeAddins Then
        qtApp.Quit ' If a change is necessary, exit QuickTest to modify the loaded add-ins
End If

If blnNeedChangeAddins Then
    Dim blnActivateOK
    blnActivateOK = qtApp.SetActiveAddins(arrTestAddins, errorDescription) ' Load the add-ins associated with the test and check whether they load successfully.
    If Not blnActivateOK Then ' If a problem occurs while loading the add-ins
        MsgBox errorDescription ' Show a message containing the error
    WScript.Quit ' And end the automation program.
    End If
End If

If Not qtApp.Launched Then ' If QuickTest is not yet open
    qtApp.Launch ' Start QuickTest (with the correct add-ins loaded)
End If
qtApp.Visible = True ' Make the QuickTest application visible

qtApp.Open "C:\Tests\Test1" ' Open the test
Set qtApp = Nothing ' Release the Application object

No comments:

Post a Comment