Parameterization in Loadrunner examples
Parameterization means Replacing hard coded values in the script with the test data is called Parameterization. Parameterization will helps to reduce script size & Avoid cache effect.Now let's see below example to understand clearly to perform parameterization of test script in loadrunner.
I am using Web Services script to perform parameterization to understand clearly,you can use Web Applications but while working with Web Services you will learn more knowledge.Let's see below example.
Web Service Request
Action()
{
web_service_call( "StepName=CreateFlightOrder_101",
"SOAPMethod=HPFlights_Service|FlightsServiceMethods|CreateFlightOrder",
"ResponseParam=response",
"Service=HPFlights_Service",
"ExpectedResponse=SoapResult",
"Snapshot=t1477723319.inf",
BEGIN_ARGUMENTS,
"xml:FlightOrder="
"<FlightOrder>"
"<Class>Economy</Class>"
"<CustomerName>Rajesh kumar</CustomerName>"
"<DepartureDate>2016-10-31</DepartureDate>"
"<FlightNumber>1089</FlightNumber>"
"<NumberOfTickets>1</NumberOfTickets>"
"</FlightOrder>",
END_ARGUMENTS,
BEGIN_RESULT,
"CreateFlightOrderResult/OrderNumber=Param_OrderNumber",
"CreateFlightOrderResult/TotalPrice=Param_TotalPrice",
END_RESULT,
LAST);
return 0;
}
For Above Create Flight Order request we are going to perform parameterization for Below tags/input arguments to complete test scenario for multiple iterations.
Flight Order
1.Class
2.Customer Name
3.DepartureDate
4.Flight Number
5.NumberOfTickets
"xml:FlightOrder="
"<FlightOrder>"
"<Class>Economy</Class>"
"<CustomerName>Rajesh kumar</CustomerName>"
"<DepartureDate>2016-10-31</DepartureDate>"
"<FlightNumber>1089</FlightNumber>"
"<NumberOfTickets>1</NumberOfTickets>"
"</FlightOrder>",
Why i have taken above input arguments means ,in order to create the Flight order you should require above input parameters to get response and i am taking just three records to do parameterization in loadrunner.
STEP 1:
1.Select the value i.e Economy in Class tag.
2.Right Click on Selected Value.
3.Click on Replace with Parameter - Create New Parameter.
[caption id="attachment_893" align="aligncenter" width="727"]
4.Enter Parameter Name as Class_name.
5.Click on Properties button.
[caption id="attachment_894" align="aligncenter" width="542"]
6.Parameter Properties window will open.
STEP 2:
Now we need to create CSV file for test data please follow below steps to create CSV file.
1.Click on Browse button and go to your script directory path E:\Loadrunner_Tutorials\FlightService.
[caption id="attachment_895" align="aligncenter" width="547"]
2.Select Files of Type as All Files and Enter File name as CreateFlightOrder.csv extension.
[caption id="attachment_896" align="aligncenter" width="579"]
3.Click on Open Button,now in Parameter Properties window File path will shows as csv file.
4.Click on Create Table button and Click on OK button.
[caption id="attachment_898" align="aligncenter" width="530"]
[caption id="attachment_897" align="aligncenter" width="465"]
5.Now it will create Given Parameter Name as Column name in table and selected Value as Value in Row.
STEP 3:
1.Now it's Time to Select some settings in Parameter Properties window for each columns to pick up Unique test data for each iteration.
2.Select Column name in Select Column tab - By Name as below screenshot and Select Next Row as Unique from drop down lists.
[caption id="attachment_899" align="aligncenter" width="546"]
3.Click on Close button.
4.Click on OK button.
5.Click on No button on HP Virtual User Generator pop up.
STEP 4:
1.Now select second value i.e CustomerName tag value i.e Rajesh kumar.
2.Right Click on Selected Value.
3.Click on Replace with Parameter - Create New Parameter.
4.Enter Parameter Name as Cust_Name.
5.Click on Properties button.
6.Now Select CreateFlightOrder.csv file.
7.Click on Add Column,click on OK button.
[caption id="attachment_900" align="aligncenter" width="420"]
8.Repeat same steps for DepartureDate,FlightNumber and NumberOfTickets,now your Parameter Properties window looks like below.
[caption id="attachment_901" align="aligncenter" width="675"]
9.Click on SAVE button in VUGen window.
10.Now Test Script will looks as below with parameters.
Action()
{
lr_start_transaction("01_CreateFlight_Order");
web_service_call( "StepName=CreateFlightOrder_101",
"SOAPMethod=HPFlights_Service|FlightsServiceMethods|CreateFlightOrder",
"ResponseParam=response",
"Service=HPFlights_Service",
"ExpectedResponse=SoapResult",
"Snapshot=t1477723319.inf",
BEGIN_ARGUMENTS,
"xml:FlightOrder="
"<FlightOrder>"
"<Class>{Class_name}</Class>"
"<CustomerName>{Cust_Name}</CustomerName>"
"<DepartureDate>{Departure_Date}</DepartureDate>"
"<FlightNumber>{Flight_Number}</FlightNumber>"
"<NumberOfTickets>{No_Tickets}</NumberOfTickets>"
"</FlightOrder>",
END_ARGUMENTS,
BEGIN_RESULT,
"CreateFlightOrderResult/OrderNumber=Param_OrderNumber",
"CreateFlightOrderResult/TotalPrice=Param_TotalPrice",
END_RESULT,
LAST);
lr_end_transaction("01_CreateFlight_Order",LR_AUTO);
return 0;
}
STEP 5:
1.Now go to Test Script directory path to Edit CSV file E:\Loadrunner_Tutorials\FlightService.
2.Open Your CSV file with Notepad++ or Notepad,you can open/edit csv file data in Parameter tab of Virtual User Generator.
3.Enter your test data in csv file.Now your csv file will display as below.
[caption id="attachment_902" align="aligncenter" width="711"]
4.Save your script in Vugen window.
STEP 6:
1.Now it's time to change settings for Run Time settings.
2.Click on Run Time Settings in Solution Explorer.
[caption id="attachment_904" align="aligncenter" width="505"]
3.In Run Time settings go to Run Login
4.Enter Number of Iterations to run ,as per CSV file 3 because 3 records i have inserted in CSV file.
[caption id="attachment_905" align="aligncenter" width="533"]
5.Click on OK
6.Go to Log - Select Extended Log-Select All Check Boxes.
[caption id="attachment_906" align="aligncenter" width="609"]
7.Click on OK button.
STEP 7:
Now Save your changes and Click on RUN icon in VUGen window.Your script execute for three time because Number of Iterations is 3 with unique test data.
[caption id="attachment_892" align="aligncenter" width="195"]
Replay Summary
[caption id="attachment_889" align="aligncenter" width="470"]
Replay Status
[caption id="attachment_890" align="aligncenter" width="799"]
Test Results
[caption id="attachment_891" align="aligncenter" width="769"]
I hope you understood the concept of Parameterization in loadrunner with above example,please share my post and provide your valuable comments,suggestions on this post.Thank you for reading.
No comments:
Post a Comment