QTP中使用强制退出程序语句小记

QTP中使用强制退出程序语句小记

1、ExitAction() 退出当前操作,无论其本地(操作)循环属性是什么。
2、ExitActionIteration() 退出操作的当前循环。
3、ExitComponent()退出当前组件并继续业务流程测试中的下一个组件,无论组件的循环设置是什么。
4、ExitComponentIteration() 退出当前组件循环并继续该组件的下一次循环,或者,如果当前组件没有其他循环,则继续业务流程测试中的下一个组件。
5、ExitGlobalIteration() 退出当前的全局循环,并使用全局数据表的下一行开始下一次循环。
6、ExitRun() 退出测试,无论其全局循环属性是什么。
7、ExitTest() 退出整个业务流程测试,无论运行时循环设置是什么。
8、ExitTestIteration() 退出业务流程测试的当前循环并继续下一次循环,或者如果没有其他运行时参数循环,则退出测试运行。 

 

 

有好几天没怎么写东西了,可能是因为白天有点事情忙着,另外就是觉得自己确实是比较懒的。感觉学习效率不如以前那么高了,有些懒散。为了每天进步一点点是卓越的开始,只好继续写了。

1)IF语句的退出。使用EXITTEST,如下所有示例子:

Dim j
For j=0 to 4
print j
if(j=3) then
Exittest
end if

Next

QTP HELP中关于EXITTEST的相关释义:

Description

Exits the entire QuickTest test or Quality Center business process test, regardless of the run-time iteration settings. The pass or fail status of the test remains as it was in the step prior to theExitTeststatement.

Syntax

ExitTest[(RetVal)]

Argument

Type

Description

RetVal
Variant
Optional.The return value.

Example

The following example uses theExitTeststatement to end the test run if a checkpoint on theuserNameedit box fails.

res = Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("userName").Check ( CheckPoint("userName") )

If res = False Then

       ExitTest

End If

2)ExitTestIteration.退出业务流程测试的当前循环并继续下一次循环,或者如果没有其他运行时参数循环,则退出测试运行。 (转).关于ExitTestIteration的QTP HELP中如下释义及例子.

Description

Exits the current iteration of the QuickTest test or Quality Center business process test and proceeds to the next iteration, or exits the test run if there are no additional run-time parameter iterations. The pass or fail status of the test iteration remains as it was in the step prior to theExitTestIterationstatement.

Syntax

ExitTestIteration[(RetVal)]

Argument

Type

Description

RetVal
Variant
Optional.The return value.

Example

The following example uses theExitTestIterationstatement to end the test run if a checkpoint on theuserNameedit box fails.

res = Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("userName").Check ( CheckPoint("userName") )

If res = False Then

       ExitTestIteration

End If

3)FOR循环语句强制退出.EXIT FOR

提供一种退出For循环的方法。只能在For...NextFor Each...Next循环中使用。Exit For将控制权转移到Next之后的语句。在嵌套的For循环中使用时,Exit For将控制权转移到循环所在位置的上一层嵌套循环。

Provides a way to exit aForloop. It can be used only in aFor...NextorFor Each...Nextloop.Exit Fortransfers control to the statement following theNextstatement. When used within nestedForloops,Exit Fortransfers control to the loop that is one nested level above the loop where it occurs.

4)DO..LOOP循环语句强制退出.EXIT DO

提供一种退出Do...Loop语句的方法。只能在Do...Loop语句中使用。Exit Do将控制权转移到Loop语句之后的语句。在嵌套的Do...Loop语句中使用时,Exit Do将控制权转移到循环所在位置的上一层嵌套循环。

Provides a way to exit aDo...Loopstatement. It can be used only inside aDo...Loopstatement.Exit Dotransfers control to the statement following theLoopstatement. When used within nestedDo...Loopstatements,Exit Dotransfers control to the loop that is one nested level above the loop where it occurs.

5)EXIT FUNCTION

立即从出现的位置退出Function过程。继续执行调用Function的语句后面的语句。

Immediately exits theFunctionprocedure in which it appears. Execution continues with the statement following the statement that called theFunction.

6)Exit Property

在Property过程中,可以使用Exit Property退出过程。程序会从调用Property过程的语句之后的语句继续执行。

Immediately exits thePropertyprocedure in which it appears. Execution continues with the statement following the statement that called thePropertyprocedure.

7)Exit Sub

立即从出现的位置退出Sub过程,继续执行调用Sub的语句后面的语句。

Immediately exits theSubprocedure in which it appears. Execution continues with the statement following the statement that called theSub.

关于以上退出语句相关的EXAMPLE如下所示:

The following example illustrates the use of theExitstatement:

Sub RandomLoop
   Dim I, MyNum
   Do   ' Set up infinite loop.
      For I = 1 To 1000   ' Loop 1000 times.
         MyNum = Int(Rnd * 100)   ' Generate random numbers.
         Select Case MyNum   ' Evaluate random number.
            Case 17: MsgBox "Case 17"ExitFor   ' If 17, exit For...Next.
            Case 29: MsgBox "Case 29"ExitDo   ' If 29, exit Do...Loop.
            Case 54: MsgBox "Case 54"ExitSub   ' If 54, exit Sub procedure.
            End Select
      Next
   Loop
End Sub

综合以上的实例,增加几个语句:

Dim j
j=1 '当J=0时会调用RandomLoop,当J=1时会强制退出IF判断语句,不会调用RANDOMLOOP并打印出该程序未调用RANDOMLOOP.
If j=0 Then
Call RandomLoop
Else
  Print "该程序未调用RandomLoop"
'exittest
End If
Sub RandomLoop
   Dim I, MyNum
   Do   ' Set up infinite loop.
      For I = 1 To 1000   ' Loop 1000 times.
         MyNum = Int(Rnd * 100)   ' Generate random numbers.
         Select Case MyNum   ' Evaluate random number.
            Case 17: MsgBox "Case 17"
               Exit For   ' If 17, exit For...Next.
            Case 29: MsgBox "Case 29"
               Exit Do   ' If 29, exit Do...Loop.
            Case 54: MsgBox "Case 54"
               Exit Sub   ' If 54, exit Sub procedure.
            End Select
      Next
   Loop
End Sub

PS:END与EXIT不一样,END是结束一个结构,EXIT是强制退出一个结构(转)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值