IntelliSense for your Custom QTP Class in 6 Steps

本文介绍了一种为QTP自定义类提供IntelliSense支持的方法,通过将QTP类转换为VB.NET代码并创建.NET库,最终通过注册表设置使QTP能够识别这些自定义类。

by Anshoo Arora on June 30, 2011 

I have been using classes in my frameworks for a long time now, and my biggest gripe about QTP is its lack of Intellisense for custom classes. It also happens to be my biggest complaint. I understand this is not high priority for HP to include in its newer versions as there is a very small group of people who use OO techniques in test automation with QTP. There has been another workaround by Yaron, who used WSC to create intellisense.

I have been researching this topic and I finally have a workaround which I have tested for for the past few weeks with great success. The best part about this workaround is, I just need to create wrappers, without including any of the code I have in my QTP function libraries. If I add a new method to my class, all I do to update the Intellisense is add the method (without the QTP code) in my VB lib, create a DLL and Register the library for COM Interop.

Let’s get working then!

Step 1: Create your QTP Modular/Custom/Generic Class

Class LoginClass
 
'#region Private Variables
    Private UserName    'As String
    Private UserRole    'As String

'#region Public Variables
    Public PageTitle    'As String
    Public LinksCount   'As Integer
    
'#region Public Methods
    Public Sub CheckLinks()
        Dim arrLinks
 
        arrLinks = Array("Home", "Register", "Language", "Sign-In")
 
        Call FunctionToCheckLinks(arrLinks)
    End Sub
 
    Public Function IsPageFound() 'As Boolean
        If Browser("title:=MyApp").Exist(15) Then IsPageFound = True
    End Function
 
'#region Class Constructor & Destructor
    Private Sub Class_Initialize()
        UserName = "test"
        UserRole = Global.UserRole
    End Sub
 
    Private Sub Class_Terminate
        'code
    End Sub
 
End Class
 
Public LoginX: Set LoginX = New LoginClass

Step 2: Converting QTP Class into VB.NET code

The next step is converting the method and property names to VB.NET. If you have never used VB.NET, don’t be scared! The syntax is quite straight-forward. The only thing to note here is, you must return values for Functions and Property Get. Also, the syntax of the Property construct differs slightly in VB.NET. Still, all you are including here are the names. You do NOT have to add the code from your QTP methods.

Always remember to include the Microsoft.VisualBasic.ComClass() flag before the class, and also, remember to make the class Public

All that goes in the VB.NET code are the names of the properties and methods. Do not include any QTP code here!

Below is a conversion of the QTP code above, to VB.NET. Notice that I have not included any of the code from my QTP class here:

SAVE THE CONVERTED CODE IN A .VB FORMAT FILE
Namespace RelevantCodes
    <Microsoft.VisualBasic.ComClass()> Public Class LoginClass
 
        Public Property PageTitle As String
            Get
                return "title"
            End Get
            Set(ByVal value As String)
                'code
            End Set
        End Property
 
        Public Property LinksCount As Integer
            Get
                return 10
            End Get
            Set(ByVal value As Integer)
            End Set
        End Property
 
        Public Sub CheckLinks()
        End Sub
 
        Public Function IsPageFound() As Boolean
        End Function
 
    End Class
End Namespace

Also remember that, your Public variables become Public Properties in VB.NET.

Step 3: Creating DLL from VB.NET Class using VBC.exe

Once our class is ready and we have saved it in .vb format, let’s create the DLL using VB’s command line compiler VBC/target:library creates a .NET code library (DLL), which is what we’re looking for.

C:\windows\Microsoft.NET\Framework\v2.0.50727\vbc.exe /target:library c:\RelevantCodes.vb

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.

Step 4: Registering Class using RegAsm.exe

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].

C:\windows\Microsoft.NET\Framework\v2.0.50727\regasm.exe c:\Relevantcodes.dll /codebase

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:

  1. Create your QTP class
  2. Convert “Public” QTP methods to VB.NET (only the method names required!)
    • Public Class
    • Microsoft.VisualBasic.ComClass() attribute
  3. Use VBC.exe to create .NET library
    • Creates a DLL in the same location as the .VB file
  4. Use RegAsm.exe Assembly Registration tool to add necessary values to Registry
  5. Add the Class Instance as a Reserved word in Registry
  6. Reference the class with another Keyword
### 配置 Vue 项目中 HTML 文件 CSS 类名的 IntelliSense 自动补全 #### 在 IntelliJ IDEA 中配置 为了在 IntelliJ IDEA 的 Vue 项目中实现 HTML 文件中 CSS 类名的自动补全功能,可以通过以下方式完成: 1. **启用插件支持** 确保已安装并启用了 `Vue.js` 插件以及 `CSS Support` 插件。如果没有安装这些插件,可以在 `File -> Settings -> Plugins` 页面搜索并安装它们[^2]。 2. **调整文件类型关联** 进入 `File -> Settings -> Editor -> File Types`,确认 `.vue` 和其他相关扩展名被正确识别为 Vue 文件类型。这有助于 IDE 更好地解析组件内的 `<style>` 块和 `<template>` 块的内容。 3. **设置全局样式路径** 如果项目的某些样式来自外部库(例如 Bootstrap 或 Tailwind),需要让 IDEA 明确知道这些样式的来源位置。通过 `File -> Settings -> Languages & Frameworks -> Style Sheets -> Imports` 添加全局样式表路径,以便其能够索引对应的类名[^1]。 4. **优化 Live Template 设置** 虽然这不是直接针对 CSS 类名补全的功能,但合理利用 `Live Templates` 可以提升开发效率。进入 `File -> Settings -> Editor -> Live Templates` 创建自定义模板来快速生成常用结构化代码片段。 --- #### 在 VS Code 中配置 对于 VS Code 用户来说,同样存在多种方法用于增强 HTML 文件内 CSS 类名的自动提示能力: 1. **安装必要的扩展** 推荐安装如下几个流行扩展: - Vetur:专为 Vue 提供语法高亮、错误检测等功能。 - Intellisense for CSS class names in HTML:专注于提供更精确的 CSS 类名建议列表[^4]。 2. **指定工作区范围内的样式资源目录** 打开 workspace settings.json 文件 (可通过命令面板输入 "Preferences: Open Workspace Settings (JSON)" 访问),加入类似下面这样的配置项: ```json { "vetur.completion.suggestImport": true, "css.classSuggestions.enabled": true, "html-css-class-completion.enableAutoInsertion": true, "files.exclude": { "**/.idea": true }, "editor.quickSuggestions": { "other": true, "comments": false, "strings": true } } ``` 上述 JSON 片段的作用包括但不限于开启字符串内部的智能感知特性,并排除掉不必要的隐藏文件夹干扰。 3. **引入第三方工具辅助分析** 当遇到复杂场景下的动态加载情况时,单独依靠编辑器内置机制可能无法完全满足需求。此时可以考虑借助 PostCSS 或者 PurgeCSS 来扫描整个应用程序所涉及的所有静态资产链接关系图谱,从而进一步提高匹配精度。 --- ### 总结 无论是使用 IntelliJ IDEA 还是 VS Code,在适当调整环境参数之后都可以显著改善开发者体验——尤其是在处理大型前端工程的时候尤为明显。以上提到的各项措施均旨在帮助用户更快捷准确地找到目标属性值组合方案的同时减少重复劳动量。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值