You can compare the run-time value of a specified object property with the expected value of that property using either programmatic descriptions or user-defined functions.
Programmatic description checks are useful in cases in which you cannot apply a regular checkpoint, for example, if the object whose properties you want to check is not stored in an object repository. You can then write the results of the check to the Test Results report.
For example, suppose you want to check the run-time value of a Web button. You can use the GetROProperty or Exist methods to retrieve the run-time value of an object or to verify whether the object exists at that point in the run session.
The following examples illustrate how to use programmatic descriptions to check whether the Continue Web button is disabled during a run session.
Using the GetROProperty method:
ActualDisabledVal = Browser(micClass:="Browser").Page(micClass:="Page").WebButton(alt:=Continue").GetROProperty("disabled")
Using the Exist method:
While Not Browser(micClass:="Browser").Page(micClass:="Page").WebButton(alt:=Continue").Exist(30)
By adding Report.ReportEvent statements, you can instruct QuickTest to send the results of a check to the Test Results.
If ActualDisabledVal = True Then
Reporter.ReportEvent micPass, "CheckContinueButton = PASS", "The Continue button is disabled, as expected."
Reporter.ReportEvent micFail, "CheckContinueButton = FAIL", "The Continue button is enabled, even though it should be disabled."
You can also create and use user-defined functions to check whether your application is functioning as expected. The following example illustrates a function that checks whether an object is disabled and returns True if the object is disabled:
'@Description Checks whether the specified test object is disabled
'@Documentation Check whether the
Public Function VerifyDisabled (obj)
' Get the disabled property from the test object
enable_property = obj.GetROProperty("disabled")
If enable_property = 1 Then ' The value is True (1)—the object is disabled
Reporter.ReportEvent micPass, "VerifyDisabled Succeeded", "The test object is disabled, as expected."
VerifyDisabled = True
Reporter.ReportEvent micFail, "VerifyDisabled Failed", "The test object is enabled, although it should be disabled."
VerifyDisabled = False
来自 “ ITPUB博客 ” ，链接：http://blog.itpub.net/16792402/viewspace-567245/，如需转载，请注明出处，否则将追究法律责任。