Parameterization in JMeter

Parameterization is the act of creating different data sets for different users in the same test script. Or Parameterization is passing some parameters or inputs to the requests, and this can be achieved by using the parameterization concept in JMeter.

Example: Running multiple users with different credentials in the same script. This makes it one of the main aspects of performance test creation.

We can achieve parameterization in JMeter in two ways:

  • JMeter Internal Parameters : in this case, we can define parameters internally and define those parameters anywhere in the JMeter.
  • Read Parameter Values from CSV/Excel file : In this case, we pass multiple parameters by creating one CSV file. We can read the parameter values from the same CSV file and give the same thing to the request. This process is also called as Data-Driven Test.

In this article, we are going to learn both the approaches of Parameterization.

HTTP Cookie Manager in JMeter

Creating JMeter Internal Parameters

  • To demonstrate JMeter Internal Parameter we are using the given URL: https://openweathermap.org/current.
  • This will provide a lot of functionalities, but we need to access through API keys that we need to generate here.
  • In this application, we can Access current weather data for any location on Earth, including over 200,000 cities!
  • Current weather is frequently updated based on global models and data from more than 40,000 weather stations. Data is available in JSON, XML, or HTML format..
  • And we can call the current weather data for one location by using City Name, By City ID, and by geographic coordinates.
  • To access all the functionalities which are present in the OpenWeatherMap website, you need an API key. by doing a Signup.
  • After the successful creation of an account, go to your home page, you will find the API keys as below.
    api-keys-genarated-jmeter
    e08f2556a390ac98e2abc422f45b38cc​
  • You can copy that generated API key and keep it with you for future use.
  • Now, let us go to the JMeter and then add the Thread Group to the Test Plan.
  • Next, add HTTP Sampler request to the Thread Group.
  • Add Server details and path parameters inside the HTTP request as below.
  • Here I am passing the city name and country code to obtain weather data of a location.
  • If you go to the OpenWeatherMap website, under by city name you find the sample codes as below.
    api.openweathermap.org/data/2.5/weather?q={city name}&appid={your api key}
    
    api.openweathermap.org/data/2.5/weather?q={city name},{state code}&appid={your api key}
    
    api.openweathermap.org/data/2.5/weather?q={city name},{state code},{country code}&appid={your api key}​
  • We had given all the details in the HTTP request to obtain the weather details by city name, API keys.
    http-request-for-openweather-map-jmeter
  • Add View Result Tree and then save and run the thread group.
  • After execution, the request has been executed successfully.
    executing-weather-deatils-request-jmeter
  • If you open the Request body, you will find the actual request sent to the JMeter.
    request-body-of-city-name-jmeter
  • And If you open the Response body, you will find the complete details of the weather in the given location.
    response-body-of-city-bengalore-jmeter

The Example demonstrates the Obtaining Weathers details of the given location by using the City ID.

  • Add one more HTTP request to the thread group and then change the Name of the request and also enter the server details and Path parameters as below.
    get-weather-details-with-city-id-jmeter
  • Here I have given APPID parameter and API keys in the Path itself.
    get-weather-details-with-city-id-jmeter
  • Save and run the thread group, after there execution, you will find the weather details of the given location by using the ID.
    get-details-by-using-city-id-jmeter
  • Till now, we access the details of weather location by using the City Name and City ID without creating the internal Parameters.
  • Now let us create an Internal Parameter to access the details.
  • If we create an internal Parameter in the Test Plan level then we can use that parameter to execute multiple Thread Groups.
  • If we create an internal Parameter in the Thread Group level then we can use that parameter to execute only that Thread Group.
  • And, If we create an internal Parameter in the Request level then we can use that parameter to execute only that Request.

The Following Example Demonstrates Accessing the Weather details of the Given location by creating an internal Parameter in the JMeter.

  • Add User-defined Config element to the Thread Group as below.
    add-user-defind-varible-jmeter
  • Inside the User Defined Variable, we are going to add Parameters such as City, Country, Id, and API key which is generated.
    user-defined-bariables-in-jmeter
  • Now, we have to use these parameters in our previous requests.
  • Go to the first request and then add a user-defined parameter inside the path as below.
    http-request-with-user-defined-variables-jmeter
    /data/2.5/weather?q=${city,${country}&APPID=${apikey}​
  • Next, add User Defined variables in the ID request also as shown below.
    /data/2.5/weather?id=${id}&APPID=${apikey}​

    adding-user-defined-variables-in-id-request-jmeter
  • Now, save and run the thread group. Both the request will execute successfully as below.
    executing-request-with-internal-parameter-jmeter
  • This is how we use the parameters anywhere inside the request by defining a list of parameters in the User Defined Variable.
  • This method helps in the reusability of Parameters.

Regular Expression Extractor in JMeter

Read Parameter Values from CSV Files in JMeter

The Following example demonstrates reading the Parameter values by creating a CSV file.

  • To Demonstrate this example, first, we need to create a CSV file in your preferred location.
  • Here I have created a CSV file as shown below.
    created-a-csv-file-jmeter
  • Next, go to the JMeter and Disable the User Defined Variable.
    disabling-user-defined-varibles-jmeter
  • We are passing the parameters in both the request in the same way but we are going to access these parameters by CSV file.
  • Next, add CSV Data Set config element to the Thread Group and then browse the CSV file in your system.
    add-csv-data-file-element-jmeter
  • Next, we need to browse the CSV file in the System, after browsing the file the remaining options will be filled according to the file structure.
    browsing-the-csv-file-jmeter
  • Now save and execute the Request, after the execution if you check the Request body and response body you will find the details.
    request-body-of-csv-file-jmeter
  • If you want to execute the request by using all the three details from the CSV file, go to the Thread group and increase the Loop count to 3 and then execute.
    executing-the-request-by-using-three-different-data-jmeter
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions