核心代码
手动关联
char str_temp[] = "";
// 手动关联
web_reg_save_param("sessionID",
"LB=<input type=hidden name=userSession value=",
"RB=>\n",
"Ord=ALL", //后续参数要sessionID_1
LAST);
登录检查点
lr_start_transaction("denglu");
web_reg_find("SaveCount=count",
"Text=Welcome, <b>AP</b>",
LAST);
判断登录检查点
if(atoi(lr_eval_string("{count}"))>0){
lr_end_transaction("denglu",LR_PASS);
}else{
lr_end_transaction("denglu",LR_FAIL);
}
订票程序关联web_reg_save_param
// 座位关联
web_reg_save_param("seatPref",
"LB=<input type=\"radio\" name=\"seatPref\" value=\"Aisle\"",
"RB= />",
"Ord=ALL",
LAST);
设置偏移量web_reg_save_param
// 偏移量
web_reg_save_param("seatPref",
"LB=<input type=\"radio\" name=\"seatPref\" ",
"RB=/>",
"Ord=ALL",
"SaveOffset=8",
"SaveLen=4",
LAST);
2种方法显示偏移量+起始便宜数
// 法1
// strncat(str_temp,lr_eval_string("{seatPref_3}"),4);
// lr_save_string(str_temp, "seatPref_3");
// 法2偏移量
lr_save_var(lr_eval_string("{seatPref_3}"),4,0,"Myseat");
设置时间地点参数
运行结果
完整代码:
Action()
{
char str_temp[] = "";
// 手动关联
web_reg_save_param("sessionID",
"LB=<input type=hidden name=userSession value=",
"RB=>\n",
"Ord=ALL", //后续参数要sessionID_1
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(14);
lr_start_transaction("denglu");
web_reg_find("SaveCount=count",
"Text=Welcome, <b>AP</b>",
LAST);
web_submit_data("login.pl",
"Action=http://localhost:1080/webtours/login.pl",
"Method=POST",
"TargetFrame=body",
"RecContentType=text/html",
"Referer=http://localhost:1080/webtours/nav.pl?in=home",
"Snapshot=t2.inf",
"Mode=HTML",
ITEMDATA,
"Name=userSession", "Value={sessionID_1}", ENDITEM,
"Name=username", "Value=AP", ENDITEM,
"Name=password", "Value=123", ENDITEM,
"Name=JSFormSubmit", "Value=off", ENDITEM,
"Name=login.x", "Value=61", ENDITEM,
"Name=login.y", "Value=13", ENDITEM,
LAST);
// lr_end_transaction("denglu", LR_AUTO);
if(atoi(lr_eval_string("{count}"))>0){
lr_end_transaction("denglu",LR_PASS);
}else{
lr_end_transaction("denglu",LR_FAIL);
}
lr_think_time(15);
lr_start_transaction("dingpiao");
lr_think_time(10);
// 座位关联
web_reg_save_param("seatPref",
"LB=<input type=\"radio\" name=\"seatPref\" value=\"Aisle\"",
"RB= />",
"Ord=ALL",
LAST);
// 偏移量
web_reg_save_param("seatPref",
"LB=<input type=\"radio\" name=\"seatPref\" ",
"RB=/>",
"Ord=ALL",
"SaveOffset=8",
"SaveLen=4",
LAST);
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=t3.inf",
"Mode=HTML",
LAST);
web_custom_request("FormDateUpdate.class",
"URL=http://localhost:1080/webtours/FormDateUpdate.class",
"Method=HEAD",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t4.inf",
"Mode=HTML",
LAST);
lr_think_time(17);
// 法1
// strncat(str_temp,lr_eval_string("{seatPref_3}"),4);
// lr_save_string(str_temp, "seatPref_3");
// 法2偏移量
lr_save_var(lr_eval_string("{seatPref_3}"),4,0,"Myseat");
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=t5.inf",
"Mode=HTML",
ITEMDATA,
"Name=advanceDiscount", "Value=0", ENDITEM,
"Name=depart", "Value={depart_city}", ENDITEM,
"Name=departDate", "Value={departdate}", ENDITEM,
"Name=arrive", "Value={arrive_city}", ENDITEM,
"Name=returnDate", "Value={returndate}", ENDITEM,
"Name=numPassengers", "Value=1", ENDITEM,
"Name=seatPref", "Value={Myseat}", ENDITEM,
"Name=seatType", "Value=Aisle", ENDITEM,
"Name=.cgifields", "Value=roundtrip", ENDITEM,
"Name=.cgifields", "Value=seatType", ENDITEM,
"Name=.cgifields", "Value=seatPref", ENDITEM,
"Name=findFlights.x", "Value=70", ENDITEM,
"Name=findFlights.y", "Value=5", ENDITEM,
LAST);
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=t6.inf",
"Mode=HTML",
ITEMDATA,
"Name=outboundFlight", "Value=000;0;{departdate}", ENDITEM,
"Name=numPassengers", "Value=1", ENDITEM,
"Name=advanceDiscount", "Value=0", ENDITEM,
"Name=seatType", "Value=Coach", ENDITEM,
"Name=seatPref", "Value={Myseat}", ENDITEM,
"Name=reserveFlights.x", "Value=8", ENDITEM,
"Name=reserveFlights.y", "Value=6", ENDITEM,
LAST);
web_reg_find("SaveCount=count_dingpiao1",
"Text=booking through Web Tours",
LAST);
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=t7.inf",
"Mode=HTML",
ITEMDATA,
"Name=firstName", "Value=A", ENDITEM,
"Name=lastName", "Value=P", ENDITEM,
"Name=address1", "Value=ZHUHAI", ENDITEM,
"Name=address2", "Value=102", ENDITEM,
"Name=pass1", "Value=A P", ENDITEM,
"Name=creditCard", "Value=23", ENDITEM,
"Name=expDate", "Value=", ENDITEM,
"Name=saveCC", "Value=on", ENDITEM,
"Name=oldCCOption", "Value=on", ENDITEM,
"Name=numPassengers", "Value=1", ENDITEM,
"Name=seatType", "Value=Coach", ENDITEM,
"Name=seatPref", "Value={Myseat}", ENDITEM,
"Name=outboundFlight", "Value=000;0;{departdate}", ENDITEM,
"Name=advanceDiscount", "Value=0", ENDITEM,
"Name=returnFlight", "Value=", ENDITEM,
"Name=JSFormSubmit", "Value=off", ENDITEM,
"Name=.cgifields", "Value=saveCC", ENDITEM,
"Name=buyFlights.x", "Value=2", ENDITEM,
"Name=buyFlights.y", "Value=16", ENDITEM,
LAST);
// atoi(lr_eval_string("{seatPref_count}"));
if(atoi(lr_eval_string("{count_dingpiao1}"))>0){
lr_end_transaction("dingpiao",LR_PASS);
}else{
lr_end_transaction("dingpiao",LR_FAIL);
}
return 0;
}
主要知识点:
web_reg_save_param
(参数名,
"LB=,
"RB=,
LAST);一定要放到这个命令的前面。
lr_save_var