Loadrunner买票流程记录(附视频)

Loadrunner登录、买票、删除票

附录中有代码

1、登录session关联、参数化

关联:

(1)找到登录接口,并分析需要用的参数

(2)找到需要参数在之前步骤出现的位置,从前到后找

关联userSession出现的位置
(3)在出现位置之前提取参数,左右边界以及转义。

     web_reg_save_param("userSession",
        "LB=userSession\" value=\"",
        "RB=\"/>",
        LAST);

(4)后者引用该参数

Value={userSession}

参数化:

(1)选中需要参数化的参数进行右键创建参数

(2)在参数文件中添加参数,选取合适的策略

2、买票业务关联、参数化

关联:

与登录类似,需要做的是将web_reg_save_param中添加"ORD=All"属性,提取在列表中。引用时用参数名加_1或_3即可。{outboundFlight_3}

<input type="radio" name="outboundFlight" value="200;635;08/18/2019" checked="checked" >Blue Sky Air 200<td align="center">8am<td align="center">$ 635</TD></TR><tr bgcolor="#EFF2F7"><td align="center">】

<input type="radio" name="outboundFlight" value="201;565;08/18/2019">Blue Sky Air 201<td align="center">1pm<td align="center">$ 565</TD></TR><tr bgcolor="#EFF2F7"><td align="center">

<input type="radio" name="outboundFlight" value="202;600;08/18/2019">Blue Sky Air 202<td align="center">5pm<td align="center">$ 600</TD></TR><tr bgcolor="#EFF2F7"><td align="center">

<input type="radio" name="outboundFlight" value="203;519;08/18/2019">Blue Sky Air 203<td align="center">11pm<td align="center">$ 519</TD></TR></table>

关联web_reg_save_param函数详情
参数化

与登录类似,需要更改的地方是1、目的地跟随出发地进行变化2、策略需要是每次出现更新

参数化策略(工作中用)
3、loadrunner删除票业务关联

(1)分析接口,需要传的参数是多个,录制脚本时多张票,进行分析

(2)snapshot中的Response Body中是录制时的记录,不是运行时的记录

(3)提取flightID进行关联,其他请求根据分析得出结果,多次尝试

(4)脚本缺点是不灵活,不能任何情况下删除所有,需要优化

<input type="checkbox" name="3" value="on" /></label></font></b>

<input type="checkbox" name="2" value="on" /></label></font></b>

<input type="hidden" name="flightID" value="7430-818-t1"  />

<input type="hidden" name="flightID" value="7503-1584-t1"  />

<input type="hidden" name="flightID" value="4462-2346-t1"  />

附录:loadrunner12中action代码,注意:需要定义参数化的参数,最后的图片中

Action()
{
/*Correlation comment - Do not change!  Original value='126856.732523289zfcfVQDpVHQVzzzHDQVfVpVfQAHf' Name ='userSession' Type ='ResponseBased'*/

    web_reg_save_param("userSession",
        "LB=userSession\" value=\"",
        "RB=\"/>",
        LAST);

    web_url("WebTours", 
        "URL=http://127.0.0.1:1080/WebTours/", 
        "TargetFrame=", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=", 
        "Snapshot=t1.inf", 
        "Mode=HTML", 
        LAST);
    //登录
    web_submit_data("login.pl",
        "Action=http://127.0.0.1:1080/cgi-bin/login.pl",
        "Method=POST",
        "TargetFrame=body",
        "RecContentType=text/html",
        "Referer=http://127.0.0.1:1080/cgi-bin/nav.pl?in=home",
        "Snapshot=t2.inf",
        "Mode=HTML",
        ITEMDATA,
        "Name=userSession", "Value={userSession}", ENDITEM,
        "Name=username", "Value={username}", ENDITEM,
        "Name=password", "Value={password}", ENDITEM,
        "Name=JSFormSubmit", "Value=off", ENDITEM,
        "Name=login.x", "Value=0", ENDITEM,
        "Name=login.y", "Value=0", ENDITEM,
        LAST);


    lr_start_transaction("买票");
    web_reg_save_param("outboundFlight",
        "LB=outboundFlight\" value=\"",
        "RB=\"",
        "ORD=All",
        LAST);

    //第一次查询票
    web_submit_data("reservations.pl", 
        "Action=http://127.0.0.1:1080/cgi-bin/reservations.pl", 
        "Method=POST", 
        "TargetFrame=", 
        "RecContentType=text/html", 
        "Referer=http://127.0.0.1:1080/cgi-bin/reservations.pl?page=welcome", 
        "Snapshot=t5.inf", 
        "Mode=HTML", 
        ITEMDATA, 
        "Name=advanceDiscount", "Value=0", ENDITEM, 
        "Name=depart", "Value={depart}", ENDITEM, 
        "Name=departDate", "Value=08/18/2019", ENDITEM, 
        "Name=arrive", "Value={arrive}", ENDITEM, 
        "Name=returnDate", "Value=08/19/2019", ENDITEM, 
        "Name=numPassengers", "Value=1", ENDITEM, 
        "Name=seatPref", "Value=Window", ENDITEM, 
        "Name=seatType", "Value=First", ENDITEM, 
        "Name=.cgifields", "Value=roundtrip", ENDITEM, 
        "Name=.cgifields", "Value=seatType", ENDITEM, 
        "Name=.cgifields", "Value=seatPref", ENDITEM, 
        "Name=findFlights.x", "Value=73", ENDITEM, 
        "Name=findFlights.y", "Value=7", ENDITEM, 
        LAST);


    //买第一张票,200航班号的票
    web_submit_data("reservations.pl_3", 
        "Action=http://127.0.0.1:1080/cgi-bin/reservations.pl", 
        "Method=POST", 
        "TargetFrame=", 
        "RecContentType=text/html", 
        "Referer=http://127.0.0.1:1080/cgi-bin/reservations.pl", 
        "Snapshot=t8.inf", 
        "Mode=HTML", 
        ITEMDATA, 
        "Name=firstName", "Value=test", ENDITEM, 
        "Name=lastName", "Value=123", ENDITEM, 
        "Name=address1", "Value=beijing", ENDITEM, 
        "Name=address2", "Value=beijing1", ENDITEM, 
        "Name=pass1", "Value=test", ENDITEM, 
        "Name=creditCard", "Value=", ENDITEM, 
        "Name=expDate", "Value=", ENDITEM, 
        "Name=oldCCOption", "Value=", ENDITEM, 
        "Name=numPassengers", "Value=1", ENDITEM, 
        "Name=seatType", "Value=First", ENDITEM, 
        "Name=seatPref", "Value=Window", ENDITEM, 
        "Name=outboundFlight", "Value={outboundFlight_1}", ENDITEM, 
        "Name=advanceDiscount", "Value=0", ENDITEM, 
        "Name=returnFlight", "Value=", ENDITEM, 
        "Name=JSFormSubmit", "Value=off", ENDITEM, 
        "Name=.cgifields", "Value=saveCC", ENDITEM, 
        "Name=buyFlights.x", "Value=51", ENDITEM, 
        "Name=buyFlights.y", "Value=5", ENDITEM, 
        LAST);
    
    //买第二张票,202航班号的票
    web_submit_data("reservations.pl_3",
        "Action=http://127.0.0.1:1080/cgi-bin/reservations.pl", 
        "Method=POST", 
        "TargetFrame=", 
        "RecContentType=text/html", 
        "Referer=http://127.0.0.1:1080/cgi-bin/reservations.pl", 
        "Snapshot=t8.inf", 
        "Mode=HTML", 
        ITEMDATA, 
        "Name=firstName", "Value=test", ENDITEM, 
        "Name=lastName", "Value=123", ENDITEM, 
        "Name=address1", "Value=beijing", ENDITEM, 
        "Name=address2", "Value=beijing1", ENDITEM, 
        "Name=pass1", "Value=test", ENDITEM, 
        "Name=creditCard", "Value=", ENDITEM, 
        "Name=expDate", "Value=", ENDITEM, 
        "Name=oldCCOption", "Value=", ENDITEM, 
        "Name=numPassengers", "Value=1", ENDITEM, 
        "Name=seatType", "Value=First", ENDITEM, 
        "Name=seatPref", "Value=Window", ENDITEM, 
        "Name=outboundFlight", "Value={outboundFlight_3}", ENDITEM, 
        "Name=advanceDiscount", "Value=0", ENDITEM, 
        "Name=returnFlight", "Value=", ENDITEM, 
        "Name=JSFormSubmit", "Value=off", ENDITEM, 
        "Name=.cgifields", "Value=saveCC", ENDITEM, 
        "Name=buyFlights.x", "Value=51", ENDITEM, 
        "Name=buyFlights.y", "Value=5", ENDITEM, 
        LAST);
    
    web_reg_save_param("outboundFlight3",
        "LB=outboundFlight\" value=\"",
        "RB=\"",
        LAST);
    
    //第二次查询票
    web_submit_data("reservations.pl", 
        "Action=http://127.0.0.1:1080/cgi-bin/reservations.pl", 
        "Method=POST", 
        "TargetFrame=", 
        "RecContentType=text/html", 
        "Referer=http://127.0.0.1:1080/cgi-bin/reservations.pl?page=welcome", 
        "Snapshot=t5.inf", 
        "Mode=HTML", 
        ITEMDATA, 
        "Name=advanceDiscount", "Value=0", ENDITEM, 
        "Name=depart", "Value={depart}", ENDITEM, 
        "Name=departDate", "Value=08/18/2019", ENDITEM, 
        "Name=arrive", "Value={arrive}", ENDITEM, 
        "Name=returnDate", "Value=08/19/2019", ENDITEM, 
        "Name=numPassengers", "Value=1", ENDITEM, 
        "Name=seatPref", "Value=Window", ENDITEM, 
        "Name=seatType", "Value=First", ENDITEM, 
        "Name=.cgifields", "Value=roundtrip", ENDITEM, 
        "Name=.cgifields", "Value=seatType", ENDITEM, 
        "Name=.cgifields", "Value=seatPref", ENDITEM, 
        "Name=findFlights.x", "Value=73", ENDITEM, 
        "Name=findFlights.y", "Value=7", ENDITEM, 
        LAST);


    //买第三张票,其他出发地目的地的票
    web_submit_data("reservations.pl_3", 
        "Action=http://127.0.0.1:1080/cgi-bin/reservations.pl", 
        "Method=POST", 
        "TargetFrame=", 
        "RecContentType=text/html", 
        "Referer=http://127.0.0.1:1080/cgi-bin/reservations.pl", 
        "Snapshot=t8.inf", 
        "Mode=HTML", 
        ITEMDATA, 
        "Name=firstName", "Value=test", ENDITEM, 
        "Name=lastName", "Value=123", ENDITEM, 
        "Name=address1", "Value=beijing", ENDITEM, 
        "Name=address2", "Value=beijing1", ENDITEM, 
        "Name=pass1", "Value=test", ENDITEM, 
        "Name=creditCard", "Value=", ENDITEM, 
        "Name=expDate", "Value=", ENDITEM, 
        "Name=oldCCOption", "Value=", ENDITEM, 
        "Name=numPassengers", "Value=1", ENDITEM, 
        "Name=seatType", "Value=First", ENDITEM, 
        "Name=seatPref", "Value=Window", ENDITEM, 
        "Name=outboundFlight", "Value={outboundFlight3}", ENDITEM, 
        "Name=advanceDiscount", "Value=0", ENDITEM, 
        "Name=returnFlight", "Value=", ENDITEM, 
        "Name=JSFormSubmit", "Value=off", ENDITEM, 
        "Name=.cgifields", "Value=saveCC", ENDITEM, 
        "Name=buyFlights.x", "Value=51", ENDITEM, 
        "Name=buyFlights.y", "Value=5", ENDITEM, 
        LAST);

    lr_end_transaction("买票",LR_AUTO);

    web_reg_save_param("flightID",
        "LB=flightID\" value=\"",
        "RB=\"",
        "ORD=All",
        LAST);

    //查票
    web_url("welcome.pl_2", 
        "URL=http://127.0.0.1:1080/cgi-bin/welcome.pl?page=itinerary", 
        "TargetFrame=", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=http://127.0.0.1:1080/cgi-bin/nav.pl?page=menu&in=flights", 
        "Snapshot=t9.inf", 
        "Mode=HTML", 
        LAST);

    
    //删除单张票
    web_submit_data("itinerary.pl", 
        "Action=http://127.0.0.1:1080/cgi-bin/itinerary.pl", 
        "Method=POST", 
        "TargetFrame=", 
        "RecContentType=text/html", 
        "Referer=http://127.0.0.1:1080/cgi-bin/itinerary.pl", 
        "Snapshot=t10.inf", 
        "Mode=HTML", 
        ITEMDATA, 
        "Name=flightID", "Value={flightID_1}", ENDITEM,
        "Name=flightID", "Value={flightID_2}", ENDITEM, 
        "Name=3", "Value=on", ENDITEM, 
        "Name=flightID", "Value={flightID_3}", ENDITEM, 
        "Name=.cgifields", "Value=1", ENDITEM, 
        "Name=.cgifields", "Value=2", ENDITEM, 
        "Name=.cgifields", "Value=3", ENDITEM, 
        "Name=removeFlights.x", "Value=58", ENDITEM, 
        "Name=removeFlights.y", "Value=16", ENDITEM, 
        LAST);
    
    //删除所有票
    web_submit_data("itinerary.pl", 
        "Action=http://127.0.0.1:1080/cgi-bin/itinerary.pl", 
        "Method=POST", 
        "TargetFrame=", 
        "RecContentType=text/html", 
        "Referer=http://127.0.0.1:1080/cgi-bin/itinerary.pl", 
        "Snapshot=t10.inf", 
        "Mode=HTML", 
        ITEMDATA, 
        "Name=flightID", "Value={flightID_1}", ENDITEM,
        "Name=flightID", "Value={flightID_2}", ENDITEM, 
        "Name=.cgifields", "Value=1", ENDITEM, 
        "Name=.cgifields", "Value=2", ENDITEM, 
        "Name=removeAllFlights.x", "Value=58", ENDITEM, 
        "Name=removeAllFlights.y", "Value=16", ENDITEM, 
        LAST);


    return 0;
}

参数化图片

username:需要注册test1密码123

username
password

password
depart

depart
 作者:科研小田 https://www.bilibili.com/read/cv3374755 出处:bilibili

视频:https://www.bilibili.com/video/BV1T4411U7Zi

上一篇:Oracle PL/SQL 中的 CHAR 和 VARCHAR2 比较


下一篇:数据结构 校园导游