|
7#
楼主 |
发表于 2007-12-21 10:24:18
|
只看该作者
给大家发Action的全部代码看看吧!欢迎大家讨论!!!!
Action()
{
int seatPrefCount; //the number of seat pref
int seatTypeCount; //the number of seat type
int flightCount; //the number of flight which we can choose from depart time to arrive city
int returnflightCount; //the number of return flight which we can choose from depart time to arrive city
int i; //use for iteration
char Type[30]; //used to store the random type
char Pref[30]; //used to store the random Pref
char Flight[100]; //used to store the random flight
char returnFlight[100]; //used to store the random returnflight
char strTemp[100]; //Temporary string
char strTmp2[100]; //Temporary string
lr_think_time(6);
//Corrlate the seat pref parameter, and get all seat pref
web_reg_save_param("seatPrefList",
"LB=<input type=\"radio\" name=\"seatPref\" value=\"",
"RB=\"",
"Ord=All",
"RelFrameId=1.2",
"Search=Body",
"IgnoreRedirections=Yes",
LAST);
//Corrlate the seat type parameter, and get all seat type
web_reg_save_param("seatTypeList",
"LB=<input type=\"radio\" name=\"seatType\" value=\"",
"RB=\"",
"Ord=All",
"RelFrameId=1.2",
"Search=Body",
"IgnoreRedirections=Yes",
LAST);
// This transaction is used to Open Flight Search Page
lr_start_transaction("OpenFlightSearchPage");
web_url("welcome.pl",
"URL=http://127.0.0.1:1080/mercuryWebTours/welcome.pl?page=search",
"Resource=0",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/mercuryWebTours/nav.pl?page=menu&in=home",
"Snapshot=t3.inf",
"Mode=HTML",
LAST);
lr_end_transaction("OpenFlightSearchPage", LR_AUTO);
lr_think_time(9);
// get the random type
seatTypeCount=aoti( lr_eval_string("{seatTypeList_count}") );
lr_message( "Type count is %d",
seatTypeCount );
sprintf( Type,
"{seatTypeList_%d}",
1 + rand() % seatTypeCount );
lr_save_string( lr_eval_string(Type),
"randomType" );
lr_message( "The random type is %s",
lr_eval_string("{randomType}") );
//get the random pref
seatPrefCount=atoi( lr_eval_string("{seatPrefList_count}") );
lr_message( "Pref count is %d",
seatPrefCount );
sprintf( Pref,
"{seatPrefList_%d}",
1 + rand() % seatPrefCount );
lr_save_string( lr_eval_string(Pref),
"randomPref" );
lr_message( "The random Pref is %s",
lr_eval_string("{randomPref}") );
//Corrlate the flight, and get all flight list
web_reg_save_param("flightList",
"LB=outboundFlight value=",
"RB=>",
"Ord=All",
"RelFrameId=1",
"Search=Body",
"IgnoreRedirections=Yes",
LAST);
//Corrlate the flight, and get all return flight list
web_reg_save_param("returnflightList",
"LB=name=returnFlight value=",
"RB=>",
"Ord=All",
"RelFrameId=1",
"Search=Body",
"IgnoreRedirections=Yes",
LAST);
// This transaction is used to search the flight
lr_start_transaction("SearchFlight");
web_submit_form("reservations.pl",
"Snapshot=t4.inf",
ITEMDATA,
"Name=depart", "Value={DepartCity}", ENDITEM,
"Name=departDate", "Value={DepartDatae}", ENDITEM,
"Name=arrive", "Value={ArriveCity}", ENDITEM,
"Name=returnDate", "Value={returnDate}", ENDITEM,
"Name=numPassengers", "Value={numPassenger}", ENDITEM,
"Name=roundtrip", "Value=on", ENDITEM,
"Name=seatPref", "Value={randomPref}", ENDITEM,
"Name=seatType", "Value={randomType}", ENDITEM,
"Name=findFlights.x", "Value=51", ENDITEM,
"Name=findFlights.y", "Value=11", ENDITEM,
LAST);
lr_end_transaction("SearchFlight", LR_AUTO);
lr_think_time(13);
lr_message("The Depart city is %s", lr_eval_string("{DepartCity}"));
lr_message("The arrive time is %s", lr_eval_string("{DepartDatae}"));
lr_message("The arrive city is %s", lr_eval_string("{ArriveCity}"));
lr_message("The return time is %s", lr_eval_string("{returnDate}"));
lr_message("The number of passengers is %s", lr_eval_string("{numPassenger}"));
lr_message("The random type is %s",lr_eval_string("{randomType}") );
lr_message("The random Pref is %s",lr_eval_string("{randomPref}") );
memset(strTmp2, 0, 100);
//get the random flight
flightCount=atoi( lr_eval_string("{flightList_count}") );
lr_message("The flight count is %d",flightCount);
for(i=1;i<=flightCount;i++)
{
sprintf(Flight,"{flightList_%d}",i );
memset(strTemp, 0, 100);
strcpy(strTemp, lr_eval_string(Flight));
if (strlen(strTemp) > 20) {
strncpy(strTmp2, strTemp, 18);
sprintf(strTemp, "flightList_%d",i);
lr_save_string(strTmp2,strTemp);
break;
}
}
sprintf( Flight,"{flightList_%d}",1 + rand() % flightCount );
lr_save_string( lr_eval_string(Flight),"RandFlight" );
lr_message( lr_eval_string("{RandFlight}") );
memset(strTmp2, 0, 100);
//get the random return flight
returnflightCount=atoi( lr_eval_string("{returnflightList_count}") );
lr_message("The return flight count is %d",returnflightCount);
for(i=1;i<=returnflightCount;i++)
{
sprintf(returnFlight,"{returnflightList_%d}",i );
memset(strTemp, 0, 100);
strcpy(strTemp, lr_eval_string(returnFlight));
if (strlen(strTemp) > 20) {
strncpy(strTmp2, strTemp, 18);
sprintf(strTemp, "returnflightList_%d",i);
lr_save_string(strTmp2,strTemp);
break;
}
}
sprintf( returnFlight,"{returnflightList_%d}",1 + rand() % returnflightCount );
lr_save_string( lr_eval_string(returnFlight),"RandreturnFlight" );
lr_message( lr_eval_string("{RandreturnFlight}") );
lr_start_transaction("ChooseFlight");
web_submit_form("reservations.pl_2",
"Snapshot=t5.inf",
ITEMDATA,
"Name=outboundFlight", "Value={RandFlight}", ENDITEM,
"Name=returnFlight", "Value={RandreturnFlight}", ENDITEM,
"Name=reserveFlights.x", "Value=78", ENDITEM,
"Name=reserveFlights.y", "Value=12", ENDITEM,
LAST);
lr_end_transaction("ChooseFlight", LR_AUTO);
lr_think_time(7);
//This transaction is used to do the payment
lr_start_transaction("Payment");
web_submit_form("reservations.pl_3",
"Snapshot=t6.inf",
ITEMDATA,
"Name=firstName", "Value=Joseph", ENDITEM,
"Name=lastName", "Value=Marshall", ENDITEM,
"Name=address1", "Value=234 Willow Drive", ENDITEM,
"Name=address2", "Value=San Jose/CA/94085", ENDITEM,
"Name=pass1", "Value=Joseph Marshall", ENDITEM,
"Name=creditCard", "Value=1212", ENDITEM,
"Name=expDate", "Value=12/07", ENDITEM,
"Name=saveCC", "Value=<OFF>", ENDITEM,
"Name=buyFlights.x", "Value=43", ENDITEM,
"Name=buyFlights.y", "Value=9", ENDITEM,
LAST);
lr_end_transaction("Payment", LR_AUTO);
return 0;
} |
|