How to choose a value randomly from the list:
"Action=http://127.0.0.1:1080/cgi-bin/reservations.pl",
"Method=POST",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/cgi-bin/reservations.pl?page=welcome",
"Snapshot=t4.inf",
"Mode=HTML",
ITEMDATA,
"Name=advanceDiscount", "Value=0", ENDITEM,
"Name=depart", "Value=London", ENDITEM,
"Name=departDate", "Value=03/28/2014", ENDITEM,
"Name=arrive", "Value=Paris", ENDITEM,
"Name=returnDate", "Value=03/29/2014", ENDITEM,
"Name=numPassengers", "Value=1", ENDITEM,
"Name=roundtrip", "Value=on", ENDITEM,
"Name=seatPref", "Value=Aisle", 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=45", ENDITEM,
"Name=findFlights.y", "Value=6", ENDITEM,
LAST);
{
int place_count,i;
char Place[100];
*/
lr_start_transaction("Flights");
web_url("welcome.pl",
"URL=http://127.0.0.1:1080/cgi-bin/welcome.pl?page=search",
"Resource=0",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/cgi-bin/nav.pl?page=menu&in=home",
"Snapshot=t3.inf",
"Mode=HTML",
LAST);
lr_end_transaction("Flights",LR_AUTO);
//Capturing the Number of places found using correlation
place_count=atoi(lr_eval_string("{places_count}"));
lr_output_message("Number of places= %d",place_count);
for(i=1;i<=place_count;i++)
{
sprintf (Place,"{places_%d}",i );
//save Place to String city
lr_save_string( lr_eval_string (Place),"city" );
lr_message( lr_eval_string("{city}") );
}
/*
Output obtained from above For Loop:
Frankfurt
London
Los Angeles
Paris
Portland
San Francisco
Seattle
Sydney
Zurich
Frankfurt
London
Los Angeles
Paris
Portland
San Francisco
Seattle
Sydney
Zurich
*/
//code to select random value
//(place_count)/2 will select only 9 out of 18.
sprintf (Place,"{places_%d}",1 + rand() % (place_count/2) );
//save Place to String depart
lr_save_string( lr_eval_string (Place),"depart" );
lr_message( "City Selected for Depart : %s" , lr_eval_string("{depart}") );
//Output: City Selected for Depart : Seattle
sprintf (Place,"{places_%d}",1 + rand() % (place_count/2) );
//save Place to String arrive
lr_save_string( lr_eval_string (Place),"arrive" );
lr_message( "City Selected for Arrival : %s" , lr_eval_string("{arrive}") );
// Output: City Selected for Arrival : Portland
lr_save_datetime("%m/%d/%Y", DATE_NOW, "departDate");
lr_output_message("Depart Date is %s",lr_eval_string("{departDate}"));
//Output: Action.c(103): Depart Date is 03/29/2014
lr_save_datetime("%m/%d/%Y", DATE_NOW+ONE_DAY*3, "returnDate");
lr_output_message("Return Date is %s",lr_eval_string("{returnDate}"));
//Output: Action.c(106): Return Date is 04/01/2014
lr_start_transaction("Find Flight");
web_submit_data("reservations.pl",
"Action=http://127.0.0.1:1080/cgi-bin/reservations.pl",
"Method=POST",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/cgi-bin/reservations.pl?page=welcome",
"Snapshot=t4.inf",
"Mode=HTML",
ITEMDATA,
"Name=advanceDiscount", "Value=0", ENDITEM,
"Name=depart", "Value={depart}", ENDITEM,
"Name=departDate", "Value={departDate}", ENDITEM,
"Name=arrive", "Value={arrive}", ENDITEM,
"Name=returnDate", "Value={returnDate}", ENDITEM,
"Name=numPassengers", "Value=1", ENDITEM,
"Name=roundtrip", "Value=on", ENDITEM,
"Name=seatPref", "Value=Aisle", 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=45", ENDITEM,
"Name=findFlights.y", "Value=6", ENDITEM,
LAST);
lr_end_transaction("Find Flight",LR_AUTO);
}
