web类协议脚本-飞机订票系统示例
Posted Conner&sun
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了web类协议脚本-飞机订票系统示例相关的知识,希望对你有一定的参考价值。
以下是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, "