知识点:![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/1c1f630e28714cbab699dd1c3d7404ff.png#pic_center)
需求:关联订票的航班信息(航班号+价格+日期)
Action()
{
char str1[]="";
int denglu = 0;
// 手动关联登录
web_reg_save_param("usersession",
"LB/IC=<input type=hidden name=userSession value=",
"RB=>\n",
"Ord=ALL",
LAST);
web_url("webtours",
"URL=http://localhost:1080/webtours",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
LAST);
lr_think_time(11);
lr_start_transaction("zong");
web_url("sign up now",
"URL=http://localhost:1080/WebTours/login.pl?username=&password=&getInfo=true",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=http://localhost:1080/WebTours/home.html",
"Snapshot=t2.inf",
"Mode=HTML",
LAST);
lr_think_time(21);
lr_start_transaction("denglu");
// 登录检查点
web_reg_find("SaveCount=denglu_count",
"Text=Welcome, <b>AP</b>, to the Web Tours reservation page",
LAST);
web_submit_data("login.pl_2",
"Action=http://localhost:1080/webtours/login.pl",
"Method=POST",
"TargetFrame=body",
"RecContentType=text/html",
"Referer=http://localhost:1080/webtours/nav.pl?in=home",
"Snapshot=t4.inf",
"Mode=HTML",
ITEMDATA,
"Name=userSession", "Value={usersession_1}", ENDITEM,
"Name=username", "Value=AP", ENDITEM,
"Name=password", "Value=123", ENDITEM,
"Name=JSFormSubmit", "Value=off", ENDITEM,
"Name=login.x", "Value=69", ENDITEM,
"Name=login.y", "Value=6", ENDITEM,
LAST);
lr_end_transaction("denglu",LR_AUTO);
denglu = atoi(lr_eval_string("{denglu_count}"));
lr_output_message("denglu=%d",denglu);
if(denglu >=1){
lr_output_message("登录成功");
}else{
lr_output_message("登录失败");
}
lr_think_time(5);
web_url("Search Flights Button",
"URL=http://localhost:1080/webtours/welcome.pl?page=search",
"TargetFrame=body",
"Resource=0",
"RecContentType=text/html",
"Referer=http://localhost:1080/webtours/nav.pl?page=menu&in=home",
"Snapshot=t5.inf",
"Mode=HTML",
LAST);
lr_think_time(37);
lr_start_transaction("Flight_piao");
// 关联座位
// 改得越多,错得越多(措施:尽量从响应内读取信息,不要额外设置参数化)
//
// web_reg_save_param("hangban",
// "LB=<input type = radio name=outboundFlight value=",
// "RB=>",
// "Ord=ALL",
// LAST);
// 关联航班号 {hangban_4} 只取{hangban_2}
web_reg_save_param("hangban",
"LB=<input type = radio name=outboundFlight value=",
"RB=>",
"Ord=ALL",
"SaveLen=3", //偏移量3位
LAST);
//查找价格
web_reg_save_param("price",
"LB=<td align=center>",
"RB=<td align=center>$",
"Ord=ALL",
LAST);
//查找时间
web_reg_save_param("time",
"LB=<td align=center>",
"RB=<td align=center>$",
"Ord=ALL",
LAST);
web_submit_data("reservations.pl",
"Action=http://localhost:1080/webtours/reservations.pl",
"Method=POST",
"TargetFrame=",
"RecContentType=text/html",
"Referer=http://localhost:1080/webtours/reservations.pl?page=welcome",
"Snapshot=t6.inf",
"Mode=HTML",
ITEMDATA,
"Name=advanceDiscount", "Value=0", ENDITEM,
"Name=depart", "Value={depart}", ENDITEM,
"Name=departDate", "Value={dapartDate}", ENDITEM,
"Name=arrive", "Value={arrive_city}", ENDITEM,
"Name=returnDate", "Value=04/27/2024", ENDITEM,
"Name=numPassengers", "Value=1", ENDITEM,
"Name=seatPref", "Value={seatPref}", ENDITEM,
"Name=seatType", "Value={seatType}", ENDITEM,
"Name=.cgifields", "Value=roundtrip", ENDITEM,
"Name=.cgifields", "Value=seatType", ENDITEM,
"Name=.cgifields", "Value=seatPref", ENDITEM,
"Name=findFlights.x", "Value=66", ENDITEM,
"Name=findFlights.y", "Value=8", ENDITEM,
LAST);
// 实现:切割航班号字符串-->切割目标:hangban_4:033;206;04/26/2024
// 法1:转换法 取{hangban_4}代码法
// strncat(str1,lr_eval_string("{hangaban_4}"),4);
// lr_save_string(str1,"hangaban_44");
// 法2:直接法
// lr_save_var(lr_eval_string("{hangban_4}"),3,0,"hangban_44");
// 法3:指针法
strcpy(str1,strtok(lr_eval_string("{hangban_2}"),";"));
lr_save_string(str1,"hangban_22"); //hangban_22 与 hangban_2 不一样,防混淆
lr_think_time(7);
web_submit_data("reservations.pl_2",
"Action=http://localhost:1080/webtours/reservations.pl",
"Method=POST",
"TargetFrame=",
"RecContentType=text/html",
"Referer=http://localhost:1080/webtours/reservations.pl",
"Snapshot=t7.inf",
"Mode=HTML",
ITEMDATA,
"Name=outboundFlight", "Value={hangban_2};202;{dapartDate}", ENDITEM,
"Name=numPassengers", "Value=1", ENDITEM,
"Name=advanceDiscount", "Value=0", ENDITEM,
"Name=seatType", "Value={seatType}", ENDITEM,
"Name=seatPref", "Value={seatPref}", ENDITEM,
"Name=reserveFlights.x", "Value=67", ENDITEM,
"Name=reserveFlights.y", "Value=12", ENDITEM,
LAST);
lr_think_time(6);
web_submit_data("reservations.pl_3",
"Action=http://localhost:1080/webtours/reservations.pl",
"Method=POST",
"TargetFrame=",
"RecContentType=text/html",
"Referer=http://localhost:1080/webtours/reservations.pl",
"Snapshot=t8.inf",
"Mode=HTML",
ITEMDATA,
"Name=firstName", "Value=A", ENDITEM,
"Name=lastName", "Value=P", ENDITEM,
"Name=address1", "Value=ZHUHAI", ENDITEM,
"Name=address2", "Value=356", ENDITEM,
"Name=pass1", "Value=A P", ENDITEM,
"Name=creditCard", "Value=56", ENDITEM,
"Name=expDate", "Value=", ENDITEM,
"Name=saveCC", "Value=on", ENDITEM,
"Name=oldCCOption", "Value=", ENDITEM,
"Name=numPassengers", "Value=1", ENDITEM,
"Name=seatType", "Value={seatType}", ENDITEM,
"Name=seatPref", "Value={seatPref}", ENDITEM,
"Name=outboundFlight", "Value={hangban_2};202;{dapartDate}", ENDITEM,
"Name=advanceDiscount", "Value=0", ENDITEM,
"Name=returnFlight", "Value=", ENDITEM,
"Name=JSFormSubmit", "Value=off", ENDITEM,
"Name=.cgifields", "Value=saveCC", ENDITEM,
"Name=buyFlights.x", "Value=68", ENDITEM,
"Name=buyFlights.y", "Value=1", ENDITEM,
LAST);
lr_end_transaction("Flight_piao",LR_AUTO);
lr_end_transaction("zong",LR_AUTO);
return 0;
}
运行结果:
3个办法关联:
实现:切割航班号字符串–>切割目标:hangban_4:033;206;04/26/2024
法1:转换法
// 法1:转换法 取{hangban_4}代码法
strncat(str1,lr_eval_string("{hangaban_4}"),4);
lr_save_string(str1,"hangaban_44");
法2:直接法
// 法2:直接法
lr_save_var(lr_eval_string("{hangban_4}"),3,0,"hangban_44");
法3:指针法
// 法3:指针法
strcpy(str1,strtok(lr_eval_string("{hangban_2}"),";"));
lr_save_string(str1,"hangban_22"); //hangban_22 与 hangban_2 不一样,防混淆
strtok--切割字符串
strcpy:复制字符串