51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 5559|回复: 12
打印 上一主题 下一主题

[转贴] Actions vs Functions in QTP 9.0

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2008-1-15 17:49:25 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我觉得这个文章总结的挺不错的。所以贴出来给大家参考

http://www.softwareinquisition.c ... functions-in-qtp-90

Actions vs Functions in QTP 9.0 April 3, 2006
Will Roden
When deciding whether a piece of code should go in a reusable action or a function, we usually favored functions in QTP 8.2. When Mercury introduced QuickTest 9, they made the argument for functions even more compelling with the Multi Document Interface. Now we can open as many function libraries as we want, but we are still limited to one test. So, if you want to edit a reusable action in another test, you have to close your current test, open the second test, make your changes, save and close the second test then reopen your original test.

In addition to that new argument for functions in QTP 9, the same old arguments from 8.2 still apply. I’ll sum up a few of the key differences between reusable actions and functions here.

Passing Data

Actions - can only accept primative data types as parameters (strings, integers, etc)

Functions - can accept arrays, dictionary objects and test objects (i.e. Pages, Frames, WebRadioGroups, etc.)

Resource Usage

Actions - For each action, there’s a folder, three separate vbs files, a local Object Repository, a subfolder containing snapshots, an Excel spreadsheet, and a few seconds of load time.

Functions - There’s the code contained in the Function, and that’s all

API

Actions - You cannot insert calls to Existing Actions through the QTP API, you can only do it through the interface

Functions - You can attach Function Libraries to Test Scripts through the QTP API

Return Values
Actions - Return values are difficult to understand and read in the syntax

Functions - Return values work like they do in other languages (i.e. as lvalues)

UPDATE:

In comments, Jugular Bean points out a significant downside to functions that I neglected above. You cannot change the number of parameters that a function accepts without affecting all calls to that function. That is a problem that used to drive me crazy. It seems like every time I put a new function in a library, the next test I write needs that function with one extra option. Now that I use the getopts function to define the parameters in my functions, I can easily add new optional parameters without messing up other tests that already call the function.
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

该用户从未签到

2#
发表于 2008-1-15 18:18:34 | 只看该作者
Action更适合没有太多编程概念的初学者使用。Function确实用起来灵活很多。
回复 支持 反对

使用道具 举报

该用户从未签到

3#
发表于 2008-1-16 11:33:01 | 只看该作者
原帖由 gy21st 于 2008-1-15 18:18 发表
Action更适合没有太多编程概念的初学者使用。Function确实用起来灵活很多。


Passing Data

if you want to pass parameter in a extra file...function can't not do this

Return Values

vb...return values is very clear? i don't think so...

i think function return values is terrible as action

[ 本帖最后由 eden_guo 于 2008-1-16 11:37 编辑 ]
回复 支持 反对

使用道具 举报

该用户从未签到

4#
发表于 2008-1-16 11:50:52 | 只看该作者
目前还是比较偏向于Function
回复 支持 反对

使用道具 举报

该用户从未签到

5#
发表于 2008-1-16 15:25:53 | 只看该作者
这个是作者的观点,可以学习一下.
回复 支持 反对

使用道具 举报

该用户从未签到

6#
发表于 2008-1-16 19:07:57 | 只看该作者
个人比较倾向function,主要是action一点不懂..
回复 支持 反对

使用道具 举报

该用户从未签到

7#
发表于 2008-3-21 15:26:12 | 只看该作者
原帖由 eden_guo 于 2008-1-16 11:33 发表


Passing Data

if you want to pass parameter in a extra file...function can't not do this

Return Values

vb...return values is very clear? i don't think so...

i think function return valu ...


As I know,you can not call to existing actions by using API of QTP
It means that calling actions is not as convenient as calling functions.
Further more,actions include a lot of binary files. Managing scripts will make you terribly crazy because of code merging and conflict.
It is easy defining funcions by using "Function ... End Funcion" and "Sub ... End Sub" instead of creating actions for a test-code programmer.
By the way, actions is designed as a normal function call for QTP actually so that there are few differences between actions and function.

[ 本帖最后由 rcpp 于 2008-3-21 15:27 编辑 ]
回复 支持 反对

使用道具 举报

该用户从未签到

8#
发表于 2008-3-21 16:33:37 | 只看该作者
Action也不是一无是处的,至少ls理解的就有点问题。
Mercury不傻,没用的东西它不会花很多工夫去搞的~

坚持使用最合适的、最便捷的~~
回复 支持 反对

使用道具 举报

该用户从未签到

9#
发表于 2008-3-21 16:47:50 | 只看该作者
个人拙见:
ACTION是关键字驱动技术的产物,目的是解决脚本的复用,如果你的框架不是关键字驱动,尽可不去理会ACTION.ACTION和FUNCTION的本质区别是有没有函数的入口点,ACTION只是一些脚本块,他没有函数的入口点,虽然我们用ACTION时也像用函数一样,但内部的实现却和调函数是不一样的.
当然如果你觉得ACTION好用,也可以尽管用!
回复 支持 反对

使用道具 举报

该用户从未签到

10#
发表于 2008-3-21 17:07:46 | 只看该作者

个人还是喜欢function多点,管理只是一个vbs而已,而且可以多个放在一起,易转移,调用,灵活性高。使用不繁琐。
从而也可以使用函数调函数实现用例的重组与新建用例,测试的灵活打打提高。
虽然action可以掉action,但还是有些复杂与不易操作,个人觉得。目前我还是喜欢用function去录制一个用例。
回复 支持 反对

使用道具 举报

  • TA的每日心情
    开心
    2016-2-27 08:48
  • 签到天数: 2 天

    连续签到: 1 天

    [LV.1]测试小兵

    11#
    发表于 2008-3-21 21:47:21 | 只看该作者
    作者全面总结了Actions 和Functions的比较结果,值得我们借鉴和学习。 可以看出,作者似乎更喜欢使用 Function。莫非作者曾经从事过软件开发?
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2016-2-27 08:48
  • 签到天数: 2 天

    连续签到: 1 天

    [LV.1]测试小兵

    12#
    发表于 2008-3-21 21:51:03 | 只看该作者
    我认真仔细阅读了一遍,可是看不懂最后说的 getopts function 是什么意思。看了一下楼主提供的链接对应的原文,才发现在它 对应着另外一个链接。
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2016-2-27 08:48
  • 签到天数: 2 天

    连续签到: 1 天

    [LV.1]测试小兵

    13#
    发表于 2008-3-21 21:52:43 | 只看该作者
    建议大家去http://www.softwareinquisition.com/  看看。那里面有不少关于WinRunner和 QTP的最新消息。I guess the owner of this website is working in HP?
    回复 支持 反对

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-5-4 19:15 , Processed in 0.080038 second(s), 27 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

    快速回复 返回顶部 返回列表