发布新日志

  • Difference between Action and Function

    2009-04-01 19:26:56

    QTP里面有Action和function,这2者有什么不同呢?在什么样的情况下选择用reusable action, 什么情况下用libray里面的function来对组织公用的方法及组件呢?

    首先:单纯从Action和Function的不同来说:

    1。 Action存有Local Objects,可以和shared object repository,shared library, Data Table, User-defined environment variable以及Recovery相关联。但function一般情况下只保存在libray file里面,本身不和object, Data Table, Environment variables 相关联。尤其是不能和object repository相关联,这就导致在用Function来管理一些对具体的objects有操作的一些组件的时候,需要同时为这个shared library file准备一个shared object repository。否则就有可能导致在function里面,对object的操作失败,找不到相应的object.

    2。 Action和Function都有input parameters和output parameters。但这之间仍然是有区别的。Function的input parameters和output parameters,因为VB script的关系,导致其只有一种类型,没有具体的parameter type。但Action不同,Action可以定义具体类型(string, number, boolean...)的input和output parameter。

    3。 保存一个Action,一般会同时保存很多文件,而function只需要一个.qfl文件即可。

    4。 在调用Action或者function的时候,function可以直接调用,action需要"Insert Call to Existing...",然后需要选定action的路径。虽然在expert view里面同样是一个语句,但如果仅仅手动输入这样一个"RunAction ....",是行不通的,必须要通过"Insert Call to Existing..."的方式加进去。

    所以总结上面的不同点,对于“什么情况下用libray里面的function来对组织公用的方法及组件呢?”这样的问题总结如下:

    1。 在Function里面尽量不要有关于object的具体操作。如果一定要有这样的function,那就必须管理相应的shared object repository。建议即使要用function来管理有关object的操作,可以用descriptive programming。

    2。 有关business的逻辑,最好用Reusable Action来保存。当然如果考虑到有太多这样可重用的Reuseable Action,而且不便保存太多Action的话,也可以用Function。

     

  • Difference between Function and Sub in VB Script

    2009-04-01 19:12:42

    转载:http://qtp9.blogspot.com/2008/11/difference-between-function-and-sub.html

    Sub Procedures
    Function Procedures
    Sub Procedures

    A sub procedure is a series of VBScript. statements, enclosed by Sub and End Sub statements which perform. actions but do not return a value. A sub procedure can take arguments. If a sub procedure doesn’t receive any arguments, its Sub statement must include an empty parenthesis().

    The following Sub procedure uses two intrinsic, or built-in, VBScript. functions, MsgBox and InputBox , to prompt a user for information. It then displays the results of a calculation based on that information. The calculation is performed in a Function procedure created using VBScript. The Function procedure is shown after the following discussion.

    Sub ConvertTemp()

    temp = InputBox("Please enter the temperature in degrees F.", 1)

    MsgBox "The temperature is " & Celsius(temp) & " degrees C."
    End Sub

    Function Procedures

    A function procedure is a series of VBScript. statements enclosed by the Function and End Function statements. A function procedure is similar to a sub procedure but it can return value to the calling function. A function procedure can take arguments (constants, variables or expressions that are passed to it by a calling procedure). If a function procedure has no arguments, it Function statement must include an empty set of parenthesis. A function returns a value by assigning a value to its name in one or more statements of the procedure. Since VBScript. has only one base data type, a function always returns a variant.

    In the following example, the Celsius function calculates degrees Celsius from degrees Fahrenheit. When the function is called from the ConvertTemp Sub procedure, a variable containing the argument value is passed to the function. The result of the calculation is returned to the calling procedure and displayed in a message box.

    Sub ConvertTemp()
    temp = InputBox("Please enter the temperature in degrees F.", 1)
    MsgBox "The temperature is " & Celsius(temp) & " degrees C."
    End Sub

    Function Celsius(fDegrees)
    Celsius = (fDegrees - 32) * 5 / 9
    End Function
    Tips:
    To get data out of a procedure, you must use a Function. Remember, a Function procedure can return a value; a Sub procedure can't.
    A Function in your code must always be used on the right side of a variable assignment or in an expression.
    To call a Sub procedure from another procedure, type the name of the procedure along with values for any required arguments, each separated by a comma. The Call statement is not required, but if you do use it, you must enclose any arguments in parentheses.
    The following example shows two calls to the MyProc procedure. One uses the Call statement in the code; the other doesn't. Both do exactly the same thing.
    Call MyProc(firstarg, secondarg)

    MyProc firstarg, secondarg

    Notice that the parentheses are omitted in the call when the Call statement isn't used.

  • 对QTP的小的总结(1)

    2009-01-18 00:04:51

    概括QTP几个关键点: Mercury company, GUI functional testing tool, Using VB scrīpt, mainly used in regression test, advanced keyword-driven.

    QTP的知识点:

    1. launch QTP and create first test. Launch QTP -> Select Add-in -> Be familiar with Keyword View and Export view, record and run -> Change actions properties(Input and out parameters/Associate repositories) -> Change test settings.

    2. Parametize. 1) action and test parameters. 2) Data table. 3)Environment parameters. 4) Randome parameters.

    3. Checkpoints. 1)Check Object property values. 2) Check tables. 3) Check Text. 4) Check Bitmaps. 5) Check XML.

    4. Objects. 1) How QTP identify objects. 2) TO and RO. 3) Object repository. 4) Change object desription properties value. 5) Configure Object identification.

    5. Descrīptive programming.

    6. Automate QTP.

    7. Automate Object repository.

Open Toolbar