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

上一篇 / 下一篇  2010-03-19 15:11:55 / 个人分类:QTP学习历程

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

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是强制退出一个结构(转)


TAG:

 

评分:0

我来说两句

Open Toolbar