Parameterization in Jmeter

Parameterization in Jmeter:

We parameterize the input to run the test with different set of data for each user. We will provide the data in a file and provide as input for a field.

For this we will create a .csv file in Excel and save it. For this example, we will parameterize four fields. They are fromPort, toPort, passFirst0 and passLast0.

 The details to corresponding fields are as follows:

We have our requests as shown below:

To add the data to the test we need to add the config element as below:
Right Click on Thread Group -> Add -> Config Element -> CSV Data Set Config

The CSV Data Set details were entered as follows:

Parameters for the CSV Data Set config is as below:
Attribute
Description
Required
Name
Descriptive name for this element that is shown in the tree.
No
Filename
Name of the file to be read. Relative file names are resolved with respect to the path of the active test plan. Absolute file names are also supported, but note that they are unlikely to work in remote mode, unless the remote server has the same directory structure. If the same physical file is referenced in two different ways - e.g. csvdata.txt and ./csvdata.txt - then these are treated as different files. If the OS does not distinguish between upper and lower case, csvData.TXT would also be opened separately.
Yes
File Encoding
The encoding to be used to read the file, if not the platform default.
No
Variable Names
List of variable names (comma-delimited). Versions of JMeter after 2.3.4 support CSV header lines: if the variable name field empty, then the first line of the file is read and interpreted as the list of column names. The names must be separated by the delimiter character. They can be quoted using double-quotes.
Yes
Delimiter
Delimiter to be used to split the records in the file. If there are fewer values on the line than there are variables the remaining variables are not updated - so they will retain their previous value (if any).
Yes
Allow quoted data?
Should the CSV file allow values to be quoted? If enabled, then values can be enclosed in - double-quote - allowing values to contain a delimeter.
Yes
Recycle on EOF?
Should the file be re-read from the beginning on reaching EOF? (default is true)
Yes
Stop thread on EOF?
Should the thread be stopped on EOF, if Recycle is false? (default is false)
Yes
Sharing mode
  • All threads - (the default) the file is shared between all the threads.
  • Current thread group - each file is opened once for each thread group in which the element appears
  • Current thread - each file is opened separately for each thread
  • Identifier - all threads sharing the same identifier share the same file. So for example if you have 4 thread groups, you could use a common id for two or more of the groups to share the file between them. Or you could use the thread number to share the file between the same thread numbers in different thread groups.
Now once the CSV Data Set is configured, we need to set the variables at appropriate position as shown:


The value is set as ${Variablename} for the required fields. For example here passFirst0 is set as ${FirstName} and passLast0 is set as ${LastName}.

Let us now verify the values are passed correctly to the required parameters from the csv file. To perform this we will add a Listener -> View Results tree as below:


In Thread group set the Number of users as 2 and run. We see that there are two sample results as we ran for two users. We check the first thread we see that fromPort is Frankfurt and toPort is London which is same as first record of our .csv file.


Now, let us verify the second thread results, we see that fromPort is London and toPort is New York. So for two different customers there are two different input provided.


In the same way we can check for the customer firstname and lastname also.


We can define one file and all requests can use same file for the parameters. In this way we can parameterize the data in Jmeter.

No comments:

Post a Comment