Yuri Bushnev is a Head of System Quality at AlphaSense, with more than 5 years of experience in Quality Assurance, DevOps and Development.

Become a JMeter and Continuous Testing Pro

Start Learning

Test Your Website Performance NOW!

arrow Please enter a URL with http(s)
Feb 12 2018

JMeter Parameterization - The Complete Guide

Parameterization is the act of creating different data sets for different users in the same test script. For example, running multiple users with different credentials in the same script. This makes it one of the main aspects in performance tests creation.


JMeter Parameterization Using External Files


In Apache JMeter™, one of the common ways to parametrize your performance scripts is to use a CSV file. The best example of CSV input files usage is a login process. If you want to test your application across different users, you need to provide a list of user credentials.


Let’s assume that we have a login request that works for one specific user:


jmeter parameterization


We can easily parametrize that request by using an external CSV file and running the script across different users. To add the CSV parameterization config:


Right click on login request -> Add -> Config Element -> CSV Data Set Config


load testing parameterization


A short explanation of ‘CSV Data Set Config’ parameters:


  • Name - element name as it will be used in the JMeter tree
  • Filename - name of the input file. Relative file names are resolved based on the path of the active test plan. Absolute filenames are also supported
  • File Encoding - encoding of input file, if it’s not the platform default
  • Variable Names - list of separated variable names that will be used as a container for parsed values. If empty, the first line of the file will be interpreted as the list of variable names
  • Delimiter - delimiter that will be used to split the parsed values from the input file
  • Allow quoted data? - true in case you want to ignore double quotes and allow such elements to contain a delimiter.
  • Recycle on EOF? - true in case the file test plan should iterate over the file more than once. It will instruct JMeter to move the cursor at the beginning of the file
  • Stop thread on EOF? - false in case of loop iteration over the CDC file and true if you want to stop the thread after reading the whole file
  • Sharing mode -
    • All threads - the file is shared between all virtual users (the default)
    • Current thread group - the file will be opened once for each thread group
    • Current thread - each file will be opened separately for each of threads
    • Identifier - all threads sharing the same identifier also share the same file


Let’s create a csv file containing different users with names and passwords:


performance testing parameterization


We can now use this file with the CSV Data Set config. In our case, it’s enough to add the “Filename” and “Variables Names” config values:


working with parameters in jmeter


The last step we have to take is to parametrize the login request with CSV variables. This can be done by substituting the initial values with appropriate variables from the “Variable Names” configuration field of the CSV Data Set Config, like this:


jmeter parameters - a guide


If we run our test script now, JMeter will substitute these variables with values from the ‘TestUsers.csv’ file. Each JMeter virtual user will receive credentials from the following csv file line.


The login request by the first user:


a guide to jmeter parameterization


The login request by the second user:


jmeter parameterization tutorial


JMeter Parameterization Using Databases


Another way to parametrize your performance scripts is to use database data through JDBC. JDBC is an application programming interface that defines how a client can access a database.


First of all, download the relevant JDBC driver to your database. For example, the mysql driver can be found here. Then, you need to add the .jar file to the test-plan by using the form below:


how to parameterize your load tests


After that, configure the database connection by using the ‘JDBC Connection Configuration’ element. Like this:


Right click on Thread Group -> Add -> Config Element -> JDBC Connection Configuration


load testing with parameters


‘JDBC Connection Configuration’ parameters:


  • Name - name of the connection configuration that will be shown in the thread group tree
  • Variable Name - name that will be used as unique identifier for the db connection (multiple connections can be used and each one will be tied to a different name)
  • Max Number of Connections - maximum number of connections allowed in the connection pool. In case of 0, each thread will get its own pool with a single connection in it
  • Max Wait (ms) - pool throws an error if the specified timeout is exceeded during db connection
  • Time Between Eviction Runs (ms) - number of milliseconds to pause between runs of the thread that evicts unused connections from the db pool
  • Auto Commit - yes to turn auto commit for related db connections
  • Test While Idle - check idle connections before an effective request is detected. More details: BasicDataSource.html#getTestWhileIdle
  • Soft Min Evictable Idle Time(ms) - period of time during which a specified connection might be idle in the db pool before it can be evicted. More details: BasicDataSource.html#getSoftMinEvictableIdleTimeMillis
  • Validation Query - healthcheck query that will be used to verify if the database is still responding
  • Database URL - JDBC connection string for the database. See here for examples
  • JDBC Driver class - appropriate name of driver class (specific for each db). For example, ‘com.mysql.jdbc.Driver’ for MySql db
  • Username - database username
  • Password - database password (will be stored unencrypted in the test plan)


In our case we need to setup the mandatory fields only:


  • Variable name Bound to Pool
  • Database URL
  • JDBC Driver class
  • Username
  • Password


The rest of the fields in the screen can be left as defaults:


configuring jmeter parameterization


Let’s assume that we stored test user credentials in the database:


jmeter load testing with parameters - learn how


Now when the database connection is configured, we can add the JDBC request itself and use its query to get all the credentials from database:


Right click on Thread Group -> Add -> Sample -> JDBC Request


By using the ‘Select Statement’ query and ‘Variable Names’ we can parse the response to custom variables.


how to run performance tests with jmeter with parameters


We will now have JMeter variables that can be used further in subsequent requests. Specified variables will be created with incremental suffix (email_1, email_2, email_3…..).


To use these variables in the ‘Login request’, we need to add a counter that will be used to access the right values from the JDBC query response. To add the ‘Counter’ element in JMeter:


Right click on Thread Group -> Add -> Config Element -> Counter


jmeter parameterization configuration


After that, we can update the ‘Login request’ using the __V function. This returns the result of evaluating a variable name expression and can be used to evaluate nested variable references:


jmeter open source load testing with parameters


The specified configuration is enough to use database values to run the script across different users:


jmeter parameterization


how to run jmeter parameterized tests


JMeter Parameterization Using the ‘Parameterized Controller’ Plugin


If you need to execute a repeating sequence of the same action with different parameters, you can use the ‘Parameterized Controller’ plugin. Let’s assume that we want to parameterize the login workflow:


working with jmeter parameters


First of all, you need to install the ‘Parameterized Controller’ plugin as it is not included into the JMeter core. Installation steps of that process can be found here.


Let’s move the ‘Login Request’ into a separate controller and disable it (right-click it and select "Disable"). This is the most preferable way to have a modules container inside your test plan and avoid using Workbench as such a container.


After the installation is over, you can add two ‘Parameterized Controller’ controllers with different user credentials:


Right click on Thread Group -> Add -> Logic Controller -> Parameterized Controller


parameterizing jmeter's login workflow


Parameterized Controllers contains the ‘User Defined Variables’ section, where you can specify your parameters. Put the credentials of the first user in the first parameterized controller and the second user credentials in the second parameterized controller.


jmeter's parameterized controller


Inside both parameterized controllers, add references to the ‘Reusable Controller’ to call the ‘Login request’ with different parameters. It can be done this way:


Right click on ‘Parameterized Controller’ -> ‘Add’ -> ‘Logic Controller’ -> ‘Module Controller’


using jmeter's parameterized controller


When running your script, you will see that the ‘Login request’ triggered each of the parameterized controllers separately. It can be very useful in case you need to run your script across different combinations of input parameters.


parameterization load testing


That’s it! You now know a number of ways to parameterize your tests. To learn more tips and hacks for building your JMeter scripts, try out our free JMeter academy.


Try out BlazeMeter, which enhances JMeter features. Request a demo, or put your URL in the box below and your test will start in minutes.

arrow Please enter a URL with http(s)

You might also find these useful:

Interested in writing for our Blog?Send us a pitch!