Geeks Talk

Prepare for your Next Interview


Welcome to the Geeks Talk forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

LoadRunner script reading csv file

This is a discussion on LoadRunner script reading csv file within the LoadRunner forums, part of the Software Testing category; Hi, I have a LoadRunner script which reads data from a csv file. Using the same web tours application, it is supposed to pick up rows from csv file for ...

Go Back   Geeks Talk > Software Testing > LoadRunner
Register Blogs FAQ Tag Cloud Calendar Mark Forums Read
  #1 (permalink)  
Old 06-11-2009
Junior Member
 
Join Date: Jun 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
one_clueless is on a distinguished road
LoadRunner script reading csv file

Hi,

I have a LoadRunner script which reads data from a csv file. Using the same web tours application, it is supposed to pick up rows from csv file for username, pwd, departure city, departure date, arrival city and return date.

I have written a code, which works fine. I am new to LoadRunner, hence I am not sure if this is the optimal solution. I have correlated the dynamic value of session id and parametrized username, pwd, etc.

My script reads csv file row into an array, then converts it into a string, then makes tokens. I have attached the parameter list screen shot. Please have a look at the code. Is there anyway of referring to the column names directly into the script?

Action()
{
char *myarray, *tkn;
char *token[80];
char tst[70], pwd,name,departurecity,departuredate, arrivalcity,returningdate;
int j, i=0;

// [WCSPARAM SessionID 41 100819.48254354fVifQAcpVDDDDDDDDVVVfptVci] Parameter {SessionID} created by Correlation Studio
web_reg_save_param( "SessionID",
"LB=userSession value=",
"RB=>",
"Ord=1",
"IgnoreRedirections=Yes",
"Search=Body",
"RelFrameId=1.2.1",
LAST );

web_url("WebTours",
"URL=http://127.0.0.1:1080/WebTours/",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
LAST);

myarray=lr_eval_string("{users}");
sprintf(tst,"%s",&myarray[0]);
token[0] = (char *)strtok(tst,",");
while(token[i]!= NULL) //ensure a pointer was found
{
i++;
token[i] = (char *)strtok(NULL, ","); //continue to tokenize the string
}

for(j = 0; j <= i-1; j++)
{
tkn=token[j];
switch (j)
{
case 0:
lr_save_string(&tkn[0],"name");
lr_output_message("Name is : %s", lr_eval_string ( "{name}" ));
break;
case 1:
lr_save_string(&tkn[0],"pwd");
lr_output_message("Password is : %s", lr_eval_string("{pwd}") );
break;
case 2:
lr_save_string(&tkn[0],"departurecity");
lr_output_message("Departure City is: %s", lr_eval_string("{departurecity}") );
break;
case 3:
lr_save_string(&tkn[0],"departuredate");
lr_output_message("Departure Date is : %s", lr_eval_string("{departuredate}") );
break;
case 4:
lr_save_string(&tkn[0],"arrivalcity");
lr_output_message("Arrival City is : %s", lr_eval_string("{arrivalcity}") );
break;
case 5:
lr_save_string(&tkn[0],"returningdate");
lr_output_message("Return Date is : %s", lr_eval_string("{returningdate}") );
break;
default: lr_output_message("Invalid option selected");
}

}

web_submit_data("login.pl",
"Action=http://127.0.0.1:1080/WebTours/login.pl",
"Method=POST",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home",
"Snapshot=t2.inf",
"Mode=HTML",
ITEMDATA,
"Name=userSession", "Value={SessionID}", ENDITEM,
"Name=username", "Value={name}", ENDITEM,
"Name=password", "Value={pwd}", ENDITEM,
"Name=JSFormSubmit", "Value=on", ENDITEM,
"Name=login.x", "Value=31", ENDITEM,
"Name=login.y", "Value=11", ENDITEM,
LAST);

web_image("Search Flights Button",
"Alt=Search Flights Button",
"Snapshot=t3.inf",
LAST);

// [WCSPARAM WCSParam_Diff1 18 640;622;07/10/2009] Parameter {WCSParam_Diff1} created by Correlation Studio
web_reg_save_param( "WCSParam_Diff1",
"LB=outboundFlight value=",
"RB= ",
"Ord=1",
"IgnoreRedirections=Yes",
"Search=Body",
"RelFrameId=1",
LAST );

web_submit_form("reservations.pl",
"Snapshot=t4.inf",
ITEMDATA,
"Name=depart", "Value={departurecity}", ENDITEM,
"Name=departDate", "Value={departuredate}", ENDITEM,
"Name=arrive", "Value={arrivalcity}", ENDITEM,
"Name=returnDate", "Value={returningdate}", ENDITEM,
"Name=numPassengers", "Value=1", ENDITEM,
"Name=roundtrip", "Value=", ENDITEM,
"Name=seatPref", "Value=None", ENDITEM,
"Name=seatType", "Value=Coach", ENDITEM,
"Name=findFlights.x", "Value=40", ENDITEM,
"Name=findFlights.y", "Value=11", ENDITEM,
LAST);

web_submit_form("reservations.pl_2",
"Snapshot=t5.inf",
ITEMDATA,
"Name=outboundFlight", "Value={WCSParam_Diff1}", ENDITEM,
"Name=reserveFlights.x", "Value=34", ENDITEM,
"Name=reserveFlights.y", "Value=6", ENDITEM,
LAST);

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=", ENDITEM,
"Name=expDate", "Value=", ENDITEM,
"Name=saveCC", "Value=", ENDITEM,
"Name=buyFlights.x", "Value=38", ENDITEM,
"Name=buyFlights.y", "Value=9", ENDITEM,
LAST);

/*sign off*/

web_image("SignOff Button",
"Alt=SignOff Button",
"Ordinal=1",
"Snapshot=t7.inf",
LAST);
return 0;
}
Attached Images
File Type: jpg parameter.JPG (82.0 KB, 1 views)
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-18-2009
Junior Member
 
Join Date: Jan 2007
Posts: 28
Thanks: 1
Thanked 0 Times in 0 Posts
abdul_sma is on a distinguished road
Re: LoadRunner script reading csv file

you have made a simple thing into a very complicated issue
create separate parameters for each value.
pick them by name from the parameter list
Reply With Quote
Reply

  Geeks Talk > Software Testing > LoadRunner

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Reading a File in Local Machine abujoy123 Oracle 2 01-02-2009 03:45 AM
Reading exe file by java code guggi Java 1 08-13-2008 05:17 AM
Is there any limit to number of columns in excel file, when reading it from script? sandeepdesai7 WinRunner 2 03-05-2008 09:46 AM
Run sample graph reading a file sheker2007 Data Warehousing 2 09-25-2007 02:59 PM
Reading a TSR file JobHelper QTP 1 07-27-2007 07:33 AM


All times are GMT -4. The time now is 09:33 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.1
Copyright © 2009 GeekInterview.com. All Rights Reserved