Loading Add-ins through VB script

In my current project we are executing the QTP scripts from Quality Center through a VB Script i.e we dont manually call QTP or QC. We use the QC OTA to achieve this. Today I came across a situation where some of the tests required Power Builder Add-in to be loaded and some the Web Add-in. I was trying to "google" on how to do this programmatically through VB script but unfortunately did not find anything. Finally I found it in the help documentation itself !!!(Remember how I mentioned earlier how powerful the help documentation is !!!!) Ok....so how do we do this...

We are using two methods here to achieve this
GetAssociatedAddinsForTest and SetActiveAddins

Description
GetAssociatedAddinsForTest Returns the collection of associated add-ins for the specified test without opening the test. This method can be called either before or after you start QuickTest (before or after the Application.Launch method).
SetActiveAddins Instructs QuickTest to load the specified add-ins when it opens. You can use this method only before starting QuickTest (before the Application.Launch statement).

Dim qtApp
Dim blnNeedChangeAddins 'check 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")
arrTestAddins = qtApp.GetAssociatedAddinsForTest("C:\Tests\Test1") ' returns 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

I dont want to have any sort of copyright or copyleft in this site but if you are reusing this code in any other site, I would appreciate you to provide this page as a link so that others get a more descriptive explanation of this concept. Your suggestion and comments are always welcome. Cheers !!!
As always,
Your friend in need,

George, Reju

Read Users' Comments (4)

4 Response to "Loading Add-ins through VB script"

  1. Anonymous Says:
    December 26, 2009 at 10:26 PM

    Havent tried this out yet. But sounds interesting.

  2. REJU GEORGE says:
    December 28, 2009 at 7:34 PM

    Yup....you would need to use this when you are starting qtp through a command line...

    George, Reju

  3. Ashish says:
    January 12, 2012 at 11:28 PM

    Hey that's nice,

    but can u let me know what should be the path of test which is inside Quality Center, while checking for addin..

  4. REJU GEORGE says:
    January 13, 2012 at 9:22 AM

    Hey Ashish, You could put the test location as a string like

    arrTestAddins = qtApp.GetAssociatedAddinsForTest ("[QualityCenter] Subject\Automated Tests\Test1")

Post a Comment

Visitors

Website Counter