利用 QTP 的 GetROProperty 和 Reporter ,可以编写自定义检查点函数替代 QTP 的 CheckPoint ,避免移植性和维护性问题。下面的 ValidateProperty 就是这样一个函数:
'Function to validate object property and report status in test results
Function ValidateProperty (Object, PropertyName, ExpectedValue, NodeName)
'First check if the object exists or not
If Not Object.Exist(0) Then
'Report a failure in the test results
Reporter.ReportEvent micFail, NodeName, "The object does not exist"
'Return false
ValidateProperty = False
Exit Function
'Check if actual property value is same a expected value
ElseIf Object.GetROProperty(PropertyName) = ExpectedValue Then
'Reporet success to test results
Reporter.ReportEvent micPass, NodeName, " Property = " & PropertyName _
& ", ExpectedValue = ActualValue = " & ExpectedValue
'Return true
ValidateProperty = True
Exit Function
Else
'Expected and actual values are different. Report failure and
'report both value to report.
Reporter.ReportEvent micFail, NodeName, " Property = " & PropertyName _
& ", ExpectedValue = " & ExpectedValue & ", Actual Value = " & _
Object.GetROProperty(PropertyName)
'Return false
ValidateProperty = False
Exit Function
End If
End Function
'Execute the checkpoint on a object
Set oLink = Browser("Web Tours").Page("Web Tours").Frame("info").Link("sign up now")
ValidateProperty oLink, "html tag", "A", " 验证链接的 html tag 属性 "
ValidateProperty oLink, "innertext", "sign up now", " 验证链接的 innertext 属性 "
ValidateProperty oLink, "text", "sign up now", " 验证链接的 text 属性 "

本文介绍如何使用QTP的GetROProperty和Reporter函数创建自定义检查点函数ValidateProperty,该函数用于验证对象属性并报告测试状态,提高脚本的移植性和维护性。
5171

被折叠的 条评论
为什么被折叠?



