自定义CheckPoint

利用 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 属性 "

 

 

 

你可能感兴趣的:(html,object,function,report,UP,browser)