51Testing软件测试论坛

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

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 3095|回复: 6
打印 上一主题 下一主题

[原创] web_reg_save_param函数ORD怎么随机选择保存在数组中的数值呢

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2009-6-9 18:04:43 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
下面是LR中的例子,如果ORD选择All, it saves the parameter values in an array.但是保存在数组里之后,怎么随机选择其中一项呢?

To reserve the default flight, save the "checked" value, and pass it to web_submit_form. The html segment for the default value is:

name=outboundFlight value=230;378;11/20/2003 checked >

/*This web_reg_save_param call applies to the following action function: web_submit_form. */

    web_reg_save_param("outFlightVal",

    "LB=outboundFlight value=", "RB= checked >", LAST);

    web_submit_form("reservations.pl",

        "Snapshot=t4.inf",

        ITEMDATA,

        "Name=depart", "Value=London", ENDITEM,

        "Name=departDate", "Value=11/20/2003", ENDITEM,

        "Name=arrive", "Value=New York", ENDITEM,

        "Name=returnDate", "Value=11/21/2003", ENDITEM,

        "Name=numPassengers", "Value=1", ENDITEM,

        "Name=roundtrip", "Value=<OFF>", ENDITEM,

        "Name=seatPref", "Value=None", ENDITEM,

        "Name=seatType", "Value=Coach", ENDITEM,

        "Name=findFlights.x", "Value=83", ENDITEM,

        "Name=findFlights.y", "Value=16", ENDITEM,

        LAST);

/*

The result of the web_reg_save_param having been called before the web_submit_form is:

Action.c(15): Notify: Saving Parameter "outFlightVal = 230;378;11/20/2003"

*/

// Now use the saved outFlightVal

    web_submit_form("reservations.pl_2",

        "Snapshot=t5.inf",

        ITEMDATA,

        "Name=outboundFlight", "Value={outFlightVal}", ENDITEM,

        "Name=reserveFlights.x", "Value=92", ENDITEM,

        "Name=reserveFlights.y", "Value=10", ENDITEM,

        LAST);

/*

Action.c(34): Notify: Parameter Substitution: parameter "outFlightVal" = "230;378;11/20/2003" */

  

Back to top

  

Case requiring handling arrays
Back to top

If you want to test the last option returned by the web_submit_form call, save all the matches and then handle the array.

This example shows the use of web_reg_save_param with "ORD=ALL" to get an array of parameters. The last item in the array is then used to correlate a web_submit_form call.

char outFlightParam[50]; // The name of the parameter for correlation

char outFlightParamVal[50]; // The formatted value of outFlightParam

/*

This web_reg_save_param call applies to the following action function, web_submit_form. Because of the "ORD=ALL" argument, it saves all the values that have the given left and right boundaries to an array of parameters.

The SaveLen argument is used to restrict the length to 18 characters because the default value is "230;378;11/20/2003 checked >". We restrict the length so as not to capture the " checked ".

*/

    web_reg_save_param("outFlightVal",

        "LB=outboundFlight value=", "RB=>",

        "ORD=ALL",

        "SaveLen=18",

        LAST);


    web_submit_form("reservations.pl",

        "Snapshot=t4.inf",

        ITEMDATA,

        "Name=depart", "Value=London", ENDITEM,

        "Name=departDate", "Value=11/20/2003", ENDITEM,

        "Name=arrive", "Value=New York", ENDITEM,

        "Name=returnDate", "Value=11/21/2003", ENDITEM,

        "Name=numPassengers", "Value=1", ENDITEM,

        "Name=roundtrip", "Value=<OFF>", ENDITEM,

        "Name=seatPref", "Value=None", ENDITEM,

        "Name=seatType", "Value=Coach", ENDITEM,

        "Name=findFlights.x", "Value=83", ENDITEM,

        "Name=findFlights.y", "Value=16", ENDITEM,

        LAST);

/*

The result of the web_reg_save_param having been called before the web_submit_form is:

Notify: Saving Parameter "outFlightVal_1 = 230;378;11/20/2003"

Notify: Saving Parameter "outFlightVal_2 = 231;337;11/20/2003"

Notify: Saving Parameter "outFlightVal_3 = 232;357;11/20/2003"

Notify: Saving Parameter "outFlightVal_4 = 233;309;11/20/2003"

Notify: Saving Parameter "outFlightVal_count = 4"

The next problem is to get the highest array element, identified with the parameter outFlightVal_count. This parameter is automatically created by the script recorder. You do not have to enter anything in the script.

*/

/* Get the name of the parameter, in this case "outFlightVal_4".

Put it in brackets so it can be an input to an lr_eval_string call.

Note that the brackets in the second argument to sprintf are not indicating a script parameter to sprintf. They are string literals that will be part of outFlightParam after the call.

In the second call to sprintf, those brackets indicate a parameter to lr_eval_string.

*/

    sprintf(outFlightParam, "{outFlightVal_%s}",

        lr_eval_string("{outFlightVal_count}"));

/* outFlightParam is now "{outFlightVal_4}" */

    /* Now get the "Value" argument for web_submit_form, in the

        format "Value=xxxx")

    */

    sprintf(outFlightParamVal, "Value=%s",

        lr_eval_string(outFlightParam));

    lr_message("The value argument is : %s", outFlightParamVal);

    // The value argument is : Value=233;309;11/20/2003

    /* Now the string outFlightParamVal can be passed

        to web_submit_form */

    web_submit_form("reservations.pl_2",

        "Snapshot=t5.inf",

        ITEMDATA,

        "Name=outboundFlight",outFlightParamVal, ENDITEM,

        "Name=reserveFlights.x", "Value=92", ENDITEM,

        "Name=reserveFlights.y", "Value=10", ENDITEM,

        LAST);
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

该用户从未签到

2#
发表于 2009-6-9 18:14:45 | 只看该作者
还在学习  不太明白  帮你顶了
回复 支持 反对

使用道具 举报

该用户从未签到

3#
 楼主| 发表于 2009-6-9 18:19:57 | 只看该作者
一样正在学习


web_reg_save_param函数,把参数项设置为ord=all,那么参数保存的结果就存在array里了,然后怎么调用呢?
回复 支持 反对

使用道具 举报

该用户从未签到

4#
发表于 2009-6-9 19:49:03 | 只看该作者
如果使用loadrunner9.1可以使用lr_paramarr_random()函数对参数数组进行处理
回复 支持 反对

使用道具 举报

该用户从未签到

5#
发表于 2009-6-9 22:45:37 | 只看该作者
做关联的值为什么要随机调用呢?应该是只有一个唯一的值要关联,关联之后也只取唯一的值啊。不明白~

Ord=all, 调用的时候就用“参数名_number“ 啊。
回复 支持 反对

使用道具 举报

该用户从未签到

6#
发表于 2009-6-9 22:54:11 | 只看该作者
就楼上的那种方法,用参数名_随机数,只要前面定义一个变量是随机数即可。

还是有需要这种关联取值的方式的时候的。如在邮件系统列表中读任意一封邮件这种就需要这种关联吧?每个不同用户都能从各自的列表中得到很多满足条件的邮件编号,读取的时候只随机选一个即可了。
回复 支持 反对

使用道具 举报

该用户从未签到

7#
发表于 2009-6-10 09:52:43 | 只看该作者
可以问一句吗   关联是不是就是利用正则表达式进行参数化  我是这么理解的  要是不这样  为什么要有边界值呢  正是因为正则表达式不是一个数据这么参数 所以指定规则    我这么理解对吗
回复 支持 反对

使用道具 举报

本版积分规则

关闭

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

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

GMT+8, 2024-11-19 10:32 , Processed in 0.074061 second(s), 25 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

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