Monday, April 2, 2012

JMeter Parameterization/Parameterizing


JMeter Parameterization:

When you want to run/execute one test plan for more than one user at the same time you go for parameterization. It is a method of generalizing an action.
We can do parametrization in two ways

Method-1:
Step1:- Record a webpage(Sample/Request) having login Scenario.
Example:-www.lowcostloadtest.com

Step2:-.Now we need a CSV data file from which we will import the values that are to be parametrized.Open notepad and enter Username and Password separated by commas.


Save the file as “test.csv”.(inside bin folder)

Step3.:-Add->ConfigElement->CSV DataSet Config.Fill the fields as follows
    Filename: test.csv (give entire path, if test.csv file is not in JMeter bin folder)
    Variable names: A, B
    Delimiter: ,
     Recycle: true
     Stop: false


Note : If test.csv file is out side the JMeter bin , please provide the entire path in FileName filed of the above screenshot. If test.csv file is in JMeter bin directory no need to provide entire path.

Note:-You can give the variable names as you wish.(like A,B).The variable names are reference  inside the sample.

Step4:- Open the login sample(request).Goto ‘Send parameter with the request’ section
Now change the value of login  field to : ${A} 
and value of Password field to : ${B}
Here A and B are the variable names set in CSV Data Set config.


Step5:-.make sure to set number of threads(users) accordingly.

Step6:-.Run the script and observe the result in result tree.


Method-2:  Using preprocessor (User Parameter)

Step1:Open a notepad and enter userid and password for three users.
Note:Save the file as test.csv. The extension csv makes it a comma separated Value (CSV) file should place in bin directory of the Jmeter

Step2: Select the Login sample and add a “User Parameter” from Thread Group->Pre Processors to it.


In parameters add three variables 'by clicking on 'Add Variable' and fill it as shown in below figure:

__CSVRead is a function which reads values from file test.csv . The second parameter of the function is the column number .Name is the variable name which is referenced in the request sample.

Step 3:select the login sample and change the values of userid and password to ${A} and ${B}.
Now run the script and observe the result in view result tree



1 comment:

Anonymous said...

also see this article parameterization in jmeter