软件测试论坛

 找回密码
 软件测试论坛注册页
查看: 1165|回复: 0

[英文资料] How to choose the option randomly in loadrunner?

[复制链接]
发表于 2011-3-16 11:27:24 | 显示全部楼层 |阅读模式
软件测试工程师就业班马上开班
本帖最后由 blog 于 2011-3-16 11:28 编辑

Description:
If one option needs to be chosen randomly in below figure, what can we do in LR?

Figure 1: This is an application for booking air tickets
Solution:
1.        Use web_reg_save_param with proper LB, RB and Ord=All to get all options’ value into an array.
2.        Get a random value from array.
3.        In next web_sumbit_form or web_url use the value.
Code:
Action()
{
//declare variables
        int flightCount;                           
    char Flight[100];                                 
    //replace with your web_reg_save_param
        web_reg_save_param("flightList",
                "LB=outboundFlight value=",
            "RB=>",
            "Ord=All",     //Make sure Ord's value is All.
        LAST);
    //replace with your web submit or web url
        web_submit_form("reservations.pl",
                "Snapshot=t4.inf",ITEMDATA,
                "Name=depart", "Value=Shanghai", ENDITEM,
                "Name=arrive", "Value=Beijing", ENDITEM,
        LAST);
        //get the count of flightList array.
    flightCount=atoi( lr_eval_string("{flightList_count}") );
    /*save random flight to Flight string.
        1 + rand() % flightCount: Generate a Random Number
        {flightList_1}:  get the first value in flightList
        */
        sprintf (Flight,"{flightList_%d}",1 + rand() % flightCount );
        //save Flight to  String RandFlight
        lr_save_string( lr_eval_string (Flight),"RandFlight" );
        lr_message( lr_eval_string("{RandFlight}") );
        //Use RandFlight in next step
        web_submit_form("reservations.pl_2",
                "Snapshot=t5.inf",ITEMDATA,
                "Name=outboundFlight", "Value={RandFlight}", ENDITEM,
        LAST);
return 0;
}

本版积分规则

Archiver|手机版|小黑屋|领测软件测试网 ( 京ICP备10010545号-5 )

GMT+8, 2020-12-6 08:25 , Processed in 0.792761 second(s), 10 queries , Xcache On.

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

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