/*
脚本使用说明:
功能:选择WebTours系统系统中最便宜的机票;
作者:Y.z
创建时间:2018/06/24
*/
int getMinPrice(char * paramName);
int getPrice(char * dst,char *str);
booking()
{
int idx,i=1;
lr_think_time(7);
web_url("welcome.pl ",
"URL=http://{IpAddress}/WebTours/welcome.pl?page=search ",
"Resource=0",
"RecContentType=text/html",
"Referer=http://{IpAddress}/WebTours/nav.pl?page=menu&in=home ",
"Snapshot=t3.inf",
"Mode=HTML",
LAST);
lr_start_transaction("continue1");
lr_think_time(45);
//关联查找最便宜的票
web_reg_save_param("p_title",
"LB=outboundFlight value=",
"RB=>Blue Sky",
"Ord=All",
LAST);
web_submit_form("reservations.pl ",
"Snapshot=t4.inf",
ITEMDATA,
"Name=depart", "Value=Frankfurt", ENDITEM,
"Name=departDate", "Value=04/15/2018", ENDITEM,
"Name=arrive", "Value=London", ENDITEM,
"Name=returnDate", "Value=04/16/2018", 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=62", ENDITEM,
"Name=findFlights.y", "Value=7", ENDITEM,
LAST);
lr_end_transaction("continue1",LR_AUTO);
lr_start_transaction("continue2");
lr_think_time(34);
//调用getMinPrice函数,寻找具有最便宜机票对应的参数ID,idx;
idx=getMinPrice("p_title");
// 本段为调试打印信息:
lr_output_message("--------------------%d",idx);
for(i=1;i<=lr_paramarr_len("p_title");i++){
lr_output_message("%s",lr_paramarr_idx("p_title",i));
}
//将关联到的数据,作为参数传递给下一个请求;
//lr_output_message("%s",lr_paramarr_idx("p_title",idx));
lr_save_string(lr_paramarr_idx("p_title",idx),"getMinPrice");
//lr_output_message("%s",lr_eval_string("{getMinPrice}"));
web_submit_form("reservations.pl_2",
"Snapshot=t5.inf",
ITEMDATA,
"Name=outboundFlight", "Value={getMinPrice}", ENDITEM,
"Name=reserveFlights.x", "Value=69", ENDITEM,
"Name=reserveFlights.y", "Value=9", ENDITEM,
LAST);
lr_end_transaction("continue2",LR_AUTO);
lr_think_time(6);
web_submit_form("reservations.pl_3",
"Snapshot=t6.inf",
ITEMDATA,
"Name=firstName", "Value=t1", ENDITEM,
"Name=lastName", "Value=t1", ENDITEM,
"Name=address1", "Value=t1", ENDITEM,
"Name=address2", "Value=t1", ENDITEM,
"Name=pass1", "Value=t1 t1", ENDITEM,
"Name=creditCard", "Value=", ENDITEM,
"Name=expDate", "Value=", ENDITEM,
"Name=saveCC", "Value=<OFF>", ENDITEM,
"Name=buyFlights.x", "Value=67", ENDITEM,
"Name=buyFlights.y", "Value=9", ENDITEM,
LAST);
return 0;
}
int getMinPrice(char * paramName){
int len=lr_paramarr_len(paramName);
int i,idx=1,min,tmp;
char dst[100];
min=getPrice(dst,lr_paramarr_idx(paramName,1));
for(i=2;i<=len;i++){
tmp=getPrice(dst,lr_paramarr_idx(paramName,i));
if(tmp<min)
{
min=tmp;
idx=i;
}
}
return idx;
}
int getPrice(char * dst,char *str){
char *start = (char *)strchr(str,';') + 1;
char *end;
strcpy(dst,start);
end=(char *)strchr(dst,';');
*end=0;
return atoi(dst);
}
脚本使用说明:
功能:选择WebTours系统系统中最便宜的机票;
作者:Y.z
创建时间:2018/06/24
*/
int getMinPrice(char * paramName);
int getPrice(char * dst,char *str);
booking()
{
int idx,i=1;
lr_think_time(7);
web_url("welcome.pl ",
"URL=http://{IpAddress}/WebTours/welcome.pl?page=search ",
"Resource=0",
"RecContentType=text/html",
"Referer=http://{IpAddress}/WebTours/nav.pl?page=menu&in=home ",
"Snapshot=t3.inf",
"Mode=HTML",
LAST);
lr_start_transaction("continue1");
lr_think_time(45);
//关联查找最便宜的票
web_reg_save_param("p_title",
"LB=outboundFlight value=",
"RB=>Blue Sky",
"Ord=All",
LAST);
web_submit_form("reservations.pl ",
"Snapshot=t4.inf",
ITEMDATA,
"Name=depart", "Value=Frankfurt", ENDITEM,
"Name=departDate", "Value=04/15/2018", ENDITEM,
"Name=arrive", "Value=London", ENDITEM,
"Name=returnDate", "Value=04/16/2018", 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=62", ENDITEM,
"Name=findFlights.y", "Value=7", ENDITEM,
LAST);
lr_end_transaction("continue1",LR_AUTO);
lr_start_transaction("continue2");
lr_think_time(34);
//调用getMinPrice函数,寻找具有最便宜机票对应的参数ID,idx;
idx=getMinPrice("p_title");
// 本段为调试打印信息:
lr_output_message("--------------------%d",idx);
for(i=1;i<=lr_paramarr_len("p_title");i++){
lr_output_message("%s",lr_paramarr_idx("p_title",i));
}
//将关联到的数据,作为参数传递给下一个请求;
//lr_output_message("%s",lr_paramarr_idx("p_title",idx));
lr_save_string(lr_paramarr_idx("p_title",idx),"getMinPrice");
//lr_output_message("%s",lr_eval_string("{getMinPrice}"));
web_submit_form("reservations.pl_2",
"Snapshot=t5.inf",
ITEMDATA,
"Name=outboundFlight", "Value={getMinPrice}", ENDITEM,
"Name=reserveFlights.x", "Value=69", ENDITEM,
"Name=reserveFlights.y", "Value=9", ENDITEM,
LAST);
lr_end_transaction("continue2",LR_AUTO);
lr_think_time(6);
web_submit_form("reservations.pl_3",
"Snapshot=t6.inf",
ITEMDATA,
"Name=firstName", "Value=t1", ENDITEM,
"Name=lastName", "Value=t1", ENDITEM,
"Name=address1", "Value=t1", ENDITEM,
"Name=address2", "Value=t1", ENDITEM,
"Name=pass1", "Value=t1 t1", ENDITEM,
"Name=creditCard", "Value=", ENDITEM,
"Name=expDate", "Value=", ENDITEM,
"Name=saveCC", "Value=<OFF>", ENDITEM,
"Name=buyFlights.x", "Value=67", ENDITEM,
"Name=buyFlights.y", "Value=9", ENDITEM,
LAST);
return 0;
}
int getMinPrice(char * paramName){
int len=lr_paramarr_len(paramName);
int i,idx=1,min,tmp;
char dst[100];
min=getPrice(dst,lr_paramarr_idx(paramName,1));
for(i=2;i<=len;i++){
tmp=getPrice(dst,lr_paramarr_idx(paramName,i));
if(tmp<min)
{
min=tmp;
idx=i;
}
}
return idx;
}
int getPrice(char * dst,char *str){
char *start = (char *)strchr(str,';') + 1;
char *end;
strcpy(dst,start);
end=(char *)strchr(dst,';');
*end=0;
return atoi(dst);
}