一个人摸索测试工具其实挺麻烦的,很多时候为了一个很小的点会花很多时间,幸亏网上有这么多的高手和前辈开的博,不然工作会更加艰难.
我写的东西也许看起来会很幼稚,因为我是个新手,写下的东西基本上都是我遇到的问题,然后解决了.写下来主要是提醒自己,以后等掌握了QTP之后再看看,或者对自己有些提示.
今天先写下遇到的这个小问题:
场景:在正式进入测试之前,对一些参数值进行了检查,如果检查不通过,就中止,并且退出脚本,最后能在报告中提示该问题所在.
解决办法:使用函数ExitAction.
看看帮助中的说明:
Descrīption
Exits the current action, regardless of its local (action) iteration attributes. The pass or fail status of the action remains as it was in the step prior to the ExitAction statement.
Note: The ExitAction statement and its return value are displayed in the Test Results.
Syntax
ExitAction[(RetVal)]
Argument |
Type |
Descrīption |
RetVal |
Variant |
Optional. The action's return value. The value can be a string or number, but it must be a constant value. It cannot be the name of a variable. |
Example
In the following example, the CheckForm action calls the GetFormVersion action. The GetFormVersion action checks whether the form is in the new version or the old version. If IsNewForm is True, then the action uses the ExitAction function to return the value 2. If IsNewForm is False, then the action uses the ExitAction function to return the value 1. The CheckForm action stores the value returned by the ExitAction statement in the FormVersion variable, and uses it in the following steps.
' Action "CheckForm"
FormVersion = RunAction("GetFormVersion", oneIteration)
If FormVersion = 2 Then
Call RunAction("CheckOldForm", oneIteration)
Else
Call RunAction("CheckNewForm", oneIteration)
End If
' Action "GetFormVersion"
If IsNewForm Then
ExitAction(2)
Else
ExitAction(1)
End If
自己的理解:ExitAction 后面带参数是可选的,如果带参数的话,一定是个常量,可以是数字和字符串类型.函数的作用是,停止当前的运行的脚本,并且返回参数值.在生成的测试报告中,也会将该结果显示出来.
用该函数实现了自己的目的.