Capture the package and write the loadrunner script of the HP aircraft booking system--booking process

I checked from the Internet, and basically I am writing how to write scripts through the recording of loadrunner, so I have the idea of ​​​​writing how to write scripts by capturing packets. The writing is relatively simple. If there is anything wrong, please point out

Tool requirements:
  • loadrunner11
  • chrome
  • Notepad++

First of all, the first step must be to log in the script, right, I won't talk about registration, just do it yourself.
Open the login interface, press F12, the packet capture interface will pop up, or it doesn't matter if you use other tools, click the login button, and the packet capture interface will have data
I won't introduce more, just look at the picture above or how to capture the bag under Baidu, I'm just teaching for entertainment.
Obviously there is a parameter called userSession, this must be a random parameter that is different every time you log in ( this parameter will appear when you check the difficulty in the administration ), where did this parameter come from?
This parameter is returned from the get request http://127.0.0.1:1080/WebTours/ , then our associated function web_reg_save_param is used. The specific script is as follows:
Of course, my IP has been parameterized, in fact, http://127.0.0.1:1080 , you can do parameterization or not. After the association, it is very simple to write the login script, as shown below
My account and password here are not related, and they will be improved later.



select flight
Open chrome's package capture F12, select the city to and from, click the submit button to view the information.


At this point, click network-reservations.pl-Headers in the packet capture interface to view the details
As shown in Figure 3 above, Form Date is the content of the request we sent. Because it is a post request, we use the function web_submit_data, as follows:
这就是选择来往城市点击提交的请求,他会返回你选择的往返城市飞机航班信息,这就是接下来我们需要做参数化的地方,点击Response会显示返回内容。

将其复制到Notepad++中
很明显能猜出选择航班我们需要的参数信息,可以先看下一个接口请求需要什么参数,再返回来查找我们需要的内容。
随便选择一个航班,点击提交,查看其接口请求信息。点击抓包界面中network-reservations.pl查看详细信息 - reservations.pl-Headers查看详细信息

查看Form Data中请求参数,很明显 outboundFlight值 012;365;04/19/2018就是我们选择的航班的信息
接下来就轮到是输入卡号和时间了吧,还是一吊样,如下图,点击提交后查看抓包信息
查看抓包内容(内容泄露我隐私了,我就打码了啊)
不用多说了吧 还是post表单形式,直接按照之前的写法写就是了

到这一步就证明你订票成功了 你可以去tinerary进行查看订票信息

注意:在写地址的时候,localhost和127.0.0.1还是有区别的,要统一下,我就是吃了没文化的亏,找了2天莫名其妙的错误。
其实上面写的不是很仔细,下面附脚本全部代码:
vuser_init()
{

/**
* 关联出来userSession,登录的时候需要这个参数
*/
web_reg_save_param("userSession",
"LB=name=userSession value=",
"RB=>",
"Search=body",
LAST);

/**
* 获取一个userSession
*/
web_url("WebTours",
"URL={ip}/WebTours/",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
LAST);

/**
* 用户登录
*/
web_submit_data("login",
"Action={ip}/WebTours/login.pl",
"Method=POST",
"RecContentType=text/html",
"Referer=",
"Snapshot=",
"Mode=HTML",
ITEMDATA,
"name=userSession","Value={userSession}",ENDITEM,//关联出来的userSession
"name=username","Value=1",ENDITEM,//账号
"name=password","Value=123456",ENDITEM,//密码
"name=login.y","Value=16",ENDITEM,
"name=login.x","Value=74",ENDITEM,
"name=login","Value=Login",ENDITEM,
"name=JSFormSubmit","Value=on",ENDITEM,
LAST);

lr_output_message("-----------------------用户名:%s",lr_eval_string("{username}"));
lr_output_message("-----------------------token为:%s",lr_eval_string("{userSession}"));
return 0;
}



Action()
{

char str[100]="";
char *Flight;


lr_save_string(lr_eval_string("{depart}"),"departCity");//将参数化depart值取出来赋予departCity
lr_save_string(lr_eval_string("{arrive}"),"arriveCity");//将参数化arrive值取出来赋arriveCity


/**
* 使用while循环
* strcmp函数对比2次取值是否相同
* 相同的话就重新赋值
*/
while(strcmp(lr_eval_string("{departCity}"),lr_eval_string("{arriveCity}"))==0){

lr_error_message("-------------城市相同,进行重新赋值-------------");
lr_save_string(lr_eval_string("{depart}"),"departCity");//将参数化depart值取出来赋予departCity
lr_save_string(lr_eval_string("{arrive}"),"arriveCity");//将参数化arrive值取出来赋arriveCity
lr_output_message("------------------------------------departCity值为:%s",lr_eval_string("{departCity}"));
lr_output_message("------------------------------------arriveCity值为:%s",lr_eval_string("{arriveCity}"));

}
//lr_output_message("------------------------------------departCity值为:%s",lr_eval_string("{departCity}"));
//lr_output_message("------------------------------------arriveCity值为:%s",lr_eval_string("{arriveCity}"));

/**
* 关联航班信息接口返回值中outboundFlight所有值
* 在选择航班接口中需要使用此值
* 因为使用常规关联,关联全部的话,第一个值会带check,所以右边界使用departDate,后续使用拼接处理
*/

web_reg_save_param("outboundFlight",
"LB=name=outboundFlight value=",
"RB={departDate}",
"Search=body",
"ORD=all",
LAST);

/**
* 开始订票
* 选择来返的城市
* 参数化来返城市
* 来返城市名字不能重复
*/
web_submit_data("选择往返城市",
"Action={ip}/WebTours/reservations.pl",
"Method=POST",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/reservations.pl?page=welcome",
"Snapshot=",
"Mode=HTML",
ITEMDATA,
"name=advanceDiscount","Value=0",ENDITEM,
"name=depart","Value={departCity}",ENDITEM,//出发城市
"name=departDate","Value={departDate}",ENDITEM,
"name=arrive","Value={arriveCity}",ENDITEM,//到达城市
"name=returnDate","Value={returnDate}",ENDITEM,
"name=numPassengers","Value=1",ENDITEM,
"name=seatPref","Value=None",ENDITEM,
"name=seatType","Value=Coach",ENDITEM,
"name=findFlights.x","Value=58",ENDITEM,
"name=findFlights.y","Value=6",ENDITEM,
"name=.cgifields","Value=roundtrip",ENDITEM,
"name=.cgifields","Value=seatType",ENDITEM,
"name=.cgifields","Value=seatPref",ENDITEM,
LAST);

Flight = lr_paramarr_random("outboundFlight");//关联参数随机取值
lr_save_string(Flight,"count");//将值赋给一个变量


strcat(strcat(str,lr_eval_string("{count}")),lr_eval_string("{departDate}"));//拼接航班信息
lr_save_string(str,"Flight_count");


//lr_output_message("--------------------------------航班号为:%s",lr_eval_string("{Flight_count}"));



/**
* 选择航班信息
* 关联参数outboundFlight,在往返城市接口返回。
*/
web_submit_data("选择航班",
"Action={ip}/WebTours/reservations.pl",
"Method=POST",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/reservations.pl",
"Snapshot=t7.inf",
"Mode=HTML",
ITEMDATA,
"name=outboundFlight","Value={Flight_count}",ENDITEM,//航班信息
"name=numPassengers","Value=1",ENDITEM,
"name=advanceDiscount","Value=0",ENDITEM,
"name=seatType","Value=Coach",ENDITEM,
"name=seatPref","Value=None",ENDITEM,
"name=reserveFlights.x","Value=67",ENDITEM,
"name=reserveFlights.y","Value=4",ENDITEM,
LAST);






web_submit_data("填写信用",
"Action={ip}/WebTours/reservations.pl",
"Method=POST",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/reservations.pl",
"Snapshot=",
"Mode=HTML",
ITEMDATA,
"name=firstName","Value=xin",ENDITEM,
"name=lastName","Value=fang",ENDITEM,
"name=address1","Value=dsadas",ENDITEM,
"name=address2","Value=dasd",ENDITEM,
"name=pass1","Value=xin fang",ENDITEM,
"name=creditCard","Value=1234567890",ENDITEM,
"name=expDate","Value={departDate}",ENDITEM,
"name=oldCCOption","Value=",ENDITEM,
"name=numPassengers","Value=1",ENDITEM,
"name=seatType","Value=Coach",ENDITEM,
"name=seatPref","Value=None",ENDITEM,
"name=outboundFlight","Value={Flight_count}",ENDITEM,
"name=advanceDiscount","Value=0",ENDITEM,
"name=returnFlight","Value=",ENDITEM,
"name=JSFormSubmit","Value=on",ENDITEM,
"name=buyFlights.x","Value=47",ENDITEM,
"name=buyFlights.y","Value=11",ENDITEM,
"name=.cgifields","Value=saveCC",ENDITEM,
LAST);

return 0;
}


重要参数化截图:




附城市全集:
Denver
Frankfurt
London
Los Angeles
Paris
Portland
San Francisco
Seattle
Sydney
Zurich


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324644603&siteId=291194637