码迷,mamicode.com
首页 > Web开发 > 详细

web类协议脚本-飞机订票系统示例

时间:2018-09-04 00:07:55      阅读:231      评论:0      收藏:0      [点我收藏+]

标签:nav   就是   ext   lse   page   span   vat   mem   sea   

以下是LR自带的飞机订票系统的Demo,希望能帮助大家。

Action()
{
 int iRand;
 int iTmp;
 char *strTmpA;
 char *strTmpB;
 char *strTmpC;
 char *position;
 if ((strTmpA = (char *)malloc(100 * sizeof(char))) == NULL) { 
     lr_output_message ("Insufficient memory available"); 
     return -1; 
    } 
 if ((strTmpB = (char *)malloc(100 * sizeof(char))) == NULL) { 
     lr_output_message ("Insufficient memory available"); 
     return -1; 
 } 
 if ((strTmpC = (char *)malloc(100 * sizeof(char))) == NULL) { 
     lr_output_message ("Insufficient memory available"); 
     return -1; 
 } 
 web_reg_save_param("userSession",
  "LB=<input type=hidden name=userSession value=",
  "RB=>",
  LAST);
 web_url("WebTours", 
  "URL=http://127.0.0.1:1080/WebTours/", 
  "TargetFrame=", 
  "Resource=0", 
  "RecContentType=text/html", 
  "Referer=", 
  "Snapshot=t2.inf", 
  "Mode=HTML", 
  LAST);
 //lr_start_transaction("login");
 //r_think_time(17);
 web_submit_data("login.pl", 
  "Action=http://127.0.0.1:1080/WebTours/login.pl", 
  "Method=POST", 
  "TargetFrame=", 
  "RecContentType=text/html", 
  "Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home", 
  "Snapshot=t3.inf", 
  "Mode=HTML", 
  ITEMDATA, 
  "Name=userSession", "Value={userSession}", ENDITEM, 
  "Name=username", "Value=demo", ENDITEM, 
  "Name=password", "Value=demo", ENDITEM, 
  "Name=JSFormSubmit", "Value=on", ENDITEM, 
  "Name=login.x", "Value=26", ENDITEM, 
  "Name=login.y", "Value=5", ENDITEM, 
  LAST);
 //lr_end_transaction("login",LR_AUTO);
 lr_start_transaction("order");
 //r_think_time(9);
web_reg_save_param("City",
  "LB=<option ",
  "RB=</option>",
  "Ord=ALL",
  LAST);
web_url("Search Flights Button", 
  "URL=http://127.0.0.1:1080/WebTours/welcome.pl?page=search", 
  "TargetFrame=body", 
  "Resource=0", 
  "RecContentType=text/html", 
  "Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home", 
  "Snapshot=t4.inf", 
  "Mode=HTML", 
  LAST);
 web_url("FormDateUpdate.class", 
  "URL=http://127.0.0.1:1080/WebTours/FormDateUpdate.class", 
  "TargetFrame=", 
  "Resource=0", 
  "RecContentType=text/html", 
  "Referer=", 
  "Mode=HTML", 
  LAST);
 web_url("CalSelect.class", 
  "URL=http://127.0.0.1:1080/WebTours/CalSelect.class", 
  "TargetFrame=", 
  "Resource=0", 
  "RecContentType=text/html", 
  "Referer=", 
  "Mode=HTML", 
  LAST);
 web_url("Calendar.class", 
  "URL=http://127.0.0.1:1080/WebTours/Calendar.class", 
  "TargetFrame=", 
  "Resource=0", 
  "RecContentType=text/html", 
  "Referer=", 
  "Mode=HTML", 
  LAST);
 //r_think_time(7);
 lr_output_message(lr_eval_string("The City count is:{City_count}"));
 iTmp = atoi(lr_eval_string("{City_count}")); //城市个数转换成int类型
 //   srand(time(NULL)); 
 iRand = rand() % (iTmp/2+1);   //随机数+1的含义是避免出现随机数是0得到City_0 加1得到的最终随机数=随机数+1;
 sprintf(strTmpA,"{City_%d}", iRand); //获取随机取到的城市编号
 sprintf(strTmpA, lr_eval_string(strTmpA)); //获取城市编号对应的值
 lr_message("The depart city is %s", strTmpA); //打印城市名称 value="Frankfurt">Frankfurt
    position = (char *)strstr(strTmpA, ">");  //定位到">"位置
 lr_save_string(position+1, "DepartCity");  //">"位置+1就是要获取的城市名称

 iRand = rand() % (iTmp/2+1);
 sprintf(strTmpB,"{City_%d}", iRand);
 sprintf(strTmpB, lr_eval_string(strTmpB));
 lr_message("The depart city is %s", strTmpB);
    position = (char *)strstr(strTmpB, ">"); 
 lr_save_string(position+1, "ArriveCity");
 while(strcmp(lr_eval_string("{DepartCity}"), lr_eval_string("{ArriveCity}")) == 0)
    {
  iRand = rand() % (iTmp/2) +1;
 
  sprintf(strTmpB,"{City_%d}", iRand);
 
  sprintf(strTmpB, lr_eval_string(strTmpB));
 
  lr_message("The depart city is %s", strTmpB);
 
  position = (char *)strstr(strTmpB, ">"); 
 
  lr_save_string(position+1, "ArriveCity");
 }
 web_reg_save_param("FlightNo",
  "LB=<input type = radio name=outboundFlight value=",
  "RB=>",
  "Ord=ALL",
  LAST);
//<input type = radio name=outboundFlight value=010;386;04/19/2015 checked >Blue Sky Air 010<
 web_submit_data("reservations.pl", 
  "Action=http://127.0.0.1:1080/WebTours/reservations.pl", 
  "Method=POST", 
  "TargetFrame=", 
  "RecContentType=text/html", 
  "Referer=http://127.0.0.1:1080/WebTours/reservations.pl?page=welcome", 
  "Snapshot=t5.inf", 
  "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={arriveDate}", ENDITEM, 
  "Name=numPassengers", "Value=1", ENDITEM, 
  "Name=seatPref", "Value=None", ENDITEM, 
  "Name=seatType", "Value=Coach", ENDITEM, 
  "Name=.cgifields", "Value=roundtrip", ENDITEM, 
  "Name=.cgifields", "Value=seatType", ENDITEM, 
  "Name=.cgifields", "Value=seatPref", ENDITEM, 
  "Name=findFlights.x", "Value=54", ENDITEM, 
  "Name=findFlights.y", "Value=5", ENDITEM, 
  LAST);
iTmp = atoi(lr_eval_string("{FlightNo_count}"));
 iRand = rand() % iTmp +1;
 //iRand = 1;
 sprintf(strTmpC,"{FlightNo_%d}", iRand);
 sprintf(strTmpC, lr_eval_string(strTmpC));
 lr_message("The Flight No is %s", strTmpC);
    position = (char *)strstr(strTmpC, "checked"); 
 if (position != NULL) {
  sprintf(position -1, "\0");
 }
 lr_save_string(strTmpC, "FlightNewNo");
 web_submit_data("reservations.pl_2", 
  "Action=http://127.0.0.1:1080/WebTours/reservations.pl", 
  "Method=POST", 
  "TargetFrame=", 
  "RecContentType=text/html", 
  "Referer=http://127.0.0.1:1080/WebTours/reservations.pl", 
  "Snapshot=t6.inf", 
  "Mode=HTML", 
  ITEMDATA, 
  "Name=outboundFlight", "Value={FlightNewNo}", 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=15", ENDITEM, 
  "Name=reserveFlights.y", "Value=2", ENDITEM, 
  LAST);
 //r_think_time(4);
 web_submit_data("reservations.pl_3", 
  "Action=http://127.0.0.1:1080/WebTours/reservations.pl", 
  "Method=POST", 
  "TargetFrame=", 
  "RecContentType=text/html", 
  "Referer=http://127.0.0.1:1080/WebTours/reservations.pl", 
  "Snapshot=t7.inf", 
  "Mode=HTML", 
  ITEMDATA, 
  "Name=firstName", "Value=Demo", ENDITEM, 
  "Name=lastName", "Value=Demo", ENDITEM, 
  "Name=address1", "Value=AAA", ENDITEM, 
  "Name=address2", "Value=", ENDITEM, 
  "Name=pass1", "Value=Demo Demo", ENDITEM, 
  "Name=creditCard", "Value=", ENDITEM, 
  "Name=expDate", "Value=", ENDITEM, 
  "Name=oldCCOption", "Value=", ENDITEM, 
  "Name=numPassengers", "Value=1", ENDITEM, 
  "Name=seatType", "Value=Coach", ENDITEM, 
  "Name=seatPref", "Value=None", ENDITEM, 
  "Name=outboundFlight", "Value={FlightNewNo}", ENDITEM, 
  "Name=advanceDiscount", "Value=0", ENDITEM, 
  "Name=returnFlight", "Value=", ENDITEM, 
  "Name=JSFormSubmit", "Value=off", ENDITEM, 
  "Name=.cgifields", "Value=saveCC", ENDITEM, 
  "Name=buyFlights.x", "Value=37", ENDITEM, 
  "Name=buyFlights.y", "Value=5", ENDITEM, 
  LAST);
 lr_end_transaction("order",LR_AUTO);
 //lr_start_transaction("logout");
 ////r_think_time(13);
 web_url("welcome.pl", 
  "URL=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=1", 
  "TargetFrame=", 
  "Resource=0", 
  "RecContentType=text/html", 
  "Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=flights", 
  "Snapshot=t8.inf", 
  "Mode=HTML", 
  LAST);
 //lr_end_transaction("logout",LR_AUTO);
 free(strTmpA);
 free(strTmpB);
 free(strTmpC);
 return 0;
}

 

web类协议脚本-飞机订票系统示例

标签:nav   就是   ext   lse   page   span   vat   mem   sea   

原文地址:https://www.cnblogs.com/ssj0723/p/9581713.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!