Executing the above syntax in cmd.exe will create a DLL file: RelevantCodes.DLL.
The path to your VBC.exe file may be different than the one I have used.
Next, we will use the .NET assembly registration tool RegAsm.exe that reads the metadata within an assembly (which we created using VBC.exe) and adds the necessary values to your registry. RegAsm.exe syntax: regasm assemblyFile [options]
.
If QTP is already open, save all your tests and resources with libraries and re-open it. Launch it, and use CreateObject to create an instance of your class to see if its working. The syntax will be:
Set InstanceName = CreateObject("Namespace.Class")
'for our class:
Set LoginX = CreateObject("RelevantCodes.LoginClass")
You must see Intellisense for the instance to ensure everything has been a success until now. If this works, rest is just adding a few values to Registry and we’re done!
Step 5: Adding the Class Reference as a QTP Reserved Word
If the above works, we’re almost done! To get the intellisense for your class, we need to navigate to the registry key below and add a few values to the new key you create. Navigate to the following key in regedit.exe:
HKEY_CURRENT_USER\Software\Mercury Interactive\QuickTest Professional\MicTest\ReservedObjects\
If the above tree does not exist, try this:
HKEY_LOCAL_MACHINE\Software\Mercury Interactive\QuickTest Professional\MicTest\ReservedObjects\
Once you’re there, add a new key under reserved objects. You can give this key any name. What I generally do is, I give the same name as my QTP class. My key, then, becomes LoginClass. Once the key is created, I create the following entries in the key: ProgID (string), UIName (string) and VisibleMode (DWord).
New Key in \ReservedObjects: Name of your QTP Class
String: ProgID, Value: Namespace.ClassName
String: UIName, Value: Name of your reference for your custom QTP class
DWord: VisibleMode, Value: 2
Therefore, in our case, considering the above, we will have the following values:
New Key in \ReservedObjects: LoginClass
String: ProgID, Value: RelevantCodes.LoginClass
String: UIName, Value: LoginX
DWord: VisibleMode, Value: 2
The final output of adding the key and all entries to it must look like below:
Step 6: Reference the Class Instance with another Keyword
Lastly, all you need to do now is add a new variable and reference your Class Instance with it (as shown by Login below):
Public LoginX: Set LoginX = New LoginClass
Public Login : Set Login = LoginX
To create your tests and to get Intellisense, remember to associate your library with the test and use the Login keyword to see the intellisense.
I need to add a new method to my existing class. How do I do that!?!!
Well, once you converted the code for your original VB.NET library, DO NOT delete it. Once you add a new Public method to your QTP class, just add it to your VB.NET code, create (update) DLL using VBC.exe and re-register it using RegAsm. The new methods will now be available.
Summary
In summary, you have to follow the below 6 steps to create Intellisense for your custom QTP class:
- Create your QTP class
- Convert “Public” QTP methods to VB.NET (only the method names required!)
- Public Class
- Microsoft.VisualBasic.ComClass() attribute
- Use VBC.exe to create .NET library
- Creates a DLL in the same location as the .VB file
- Use RegAsm.exe Assembly Registration tool to add necessary values to Registry
- Add the Class Instance as a Reserved word in Registry
- Reference the class with another Keyword