IntelliSense for your Custom QTP Class in 6 Steps

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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1 目标检测的定义 目标检测(Object Detection)的任务是找出图像中所有感兴趣的目标(物体),确定它们的类别和位置,是计算机视觉领域的核心问题之一。由于各类物体有不同的外观、形状和姿态,加上成像时光照、遮挡等因素的干扰,目标检测一直是计算机视觉领域最具有挑战性的问题。 目标检测任务可分为两个关键的子任务,目标定位和目标分类。首先检测图像中目标的位置(目标定位),然后给出每个目标的具体类别(目标分类)。输出结果是一个边界框(称为Bounding-box,一般形式为(x1,y1,x2,y2),表示框的左上角坐标和右下角坐标),一个置信度分数(Confidence Score),表示边界框中是否包含检测对象的概率和各个类别的概率(首先得到类别概率,经过Softmax可得到类别标签)。 1.1 Two stage方法 目前主流的基于深度学习的目标检测算法主要分为两类:Two stage和One stage。Two stage方法将目标检测过程分为两个阶段。第一个阶段是 Region Proposal 生成阶段,主要用于生成潜在的目标候选框(Bounding-box proposals)。这个阶段通常使用卷积神经网络(CNN)从输入图像中提取特征,然后通过一些技巧(如选择性搜索)来生成候选框。第二个阶段是分类和位置精修阶段,将第一个阶段生成的候选框输入到另一个 CNN 中进行分类,并根据分类结果对候选框的位置进行微调。Two stage 方法的优点是准确度较高,缺点是速度相对较慢。 常见Tow stage目标检测算法有:R-CNN系列、SPPNet等。 1.2 One stage方法 One stage方法直接利用模型提取特征值,并利用这些特征值进行目标的分类和定位,不需要生成Region Proposal。这种方法的优点是速度快,因为省略了Region Proposal生成的过程。One stage方法的缺点是准确度相对较低,因为它没有对潜在的目标进行预先筛选。 常见的One stage目标检测算法有:YOLO系列、SSD系列和RetinaNet等。 2 常见名词解释 2.1 NMS(Non-Maximum Suppression) 目标检测模型一般会给出目标的多个预测边界框,对成百上千的预测边界框都进行调整肯定是不可行的,需要对这些结果先进行一个大体的挑选。NMS称为非极大值抑制,作用是从众多预测边界框中挑选出最具代表性的结果,这样可以加快算法效率,其主要流程如下: 设定一个置信度分数阈值,将置信度分数小于阈值的直接过滤掉 将剩下框的置信度分数从大到小排序,选中值最大的框 遍历其余的框,如果和当前框的重叠面积(IOU)大于设定的阈值(一般为0.7),就将框删除(超过设定阈值,认为两个框的里面的物体属于同一个类别) 从未处理的框中继续选一个置信度分数最大的,重复上述过程,直至所有框处理完毕 2.2 IoU(Intersection over Union) 定义了两个边界框的重叠度,当预测边界框和真实边界框差异很小时,或重叠度很大时,表示模型产生的预测边界框很准确。边界框A、B的IOU计算公式为: 2.3 mAP(mean Average Precision) mAP即均值平均精度,是评估目标检测模型效果的最重要指标,这个值介于0到1之间,且越大越好。mAP是AP(Average Precision)的平均值,那么首先需要了解AP的概念。想要了解AP的概念,还要首先了解目标检测中Precision和Recall的概念。 首先我们设置置信度阈值(Confidence Threshold)和IoU阈值(一般设置为0.5,也会衡量0.75以及0.9的mAP值): 当一个预测边界框被认为是True Positive(TP)时,需要同时满足下面三个条件: Confidence Score > Confidence Threshold 预测类别匹配真实值(Ground truth)的类别 预测边界框的IoU大于设定的IoU阈值 不满足条件2或条件3,则认为是False Positive(FP)。当对应同一个真值有多个预测结果时,只有最高置信度分数的预测结果被认为是True Positive,其余被认为是False Positive。 Precision和Recall的概念如下图所示: Precision表示TP与预测边界框数量的比值 Recall表示TP与真实边界框数量的比值 改变不同的置信度阈值,可以获得多组Precision和Recall,Recall放X轴,Precision放Y轴,可以画出一个Precision-Recall曲线,简称P-R
图像识别技术在病虫害检测中的应用是一个快速发展的领域,它结合了计算机视觉和机器学习算法来自动识别和分类植物上的病虫害。以下是这一技术的一些关键步骤和组成部分: 1. **数据收集**:首先需要收集大量的植物图像数据,这些数据包括健康植物的图像以及受不同病虫害影响的植物图像。 2. **图像预处理**:对收集到的图像进行处理,以提高后续分析的准确性。这可能包括调整亮度、对比度、去噪、裁剪、缩放等。 3. **特征提取**:从图像中提取有助于识别病虫害的特征。这些特征可能包括颜色、纹理、形状、边缘等。 4. **模型训练**:使用机器学习算法(如支持向量机、随机森林、卷积神经网络等)来训练模型。训练过程中,算法会学习如何根据提取的特征来识别不同的病虫害。 5. **模型验证和测试**:在独立的测试集上验证模型的性能,以确保其准确性和泛化能力。 6. **部署和应用**:将训练好的模型部署到实际的病虫害检测系统中,可以是移动应用、网页服务或集成到智能农业设备中。 7. **实时监测**:在实际应用中,系统可以实时接收植物图像,并快速给出病虫害的检测结果。 8. **持续学习**:随着时间的推移,系统可以不断学习新的病虫害样本,以提高其识别能力。 9. **用户界面**:为了方便用户使用,通常会有一个用户友好的界面,显示检测结果,并提供进一步的指导或建议。 这项技术的优势在于它可以快速、准确地识别出病虫害,甚至在早期阶段就能发现问题,从而及时采取措施。此外,它还可以减少对化学农药的依赖,支持可持续农业发展。随着技术的不断进步,图像识别在病虫害检测中的应用将越来越广泛。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值