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:
  • 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.
  • 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.{city name}&appid={your api key}{city name},{state code}&appid={your api key}{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.
  • Add View Result Tree and then save and run the thread group.
  • After execution, the request has been executed successfully.
  • If you open the Request body, you will find the actual request sent to the JMeter.
  • And If you open the Response body, you will find the complete details of the weather in the given location.

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.
  • Here I have given APPID parameter and API keys in the Path itself.
  • Save and run the thread group, after there execution, you will find the weather details of the given location by using the ID.
  • 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.
  • Inside the User Defined Variable, we are going to add Parameters such as City, Country, Id, and API key which is generated.
  • 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.
  • Next, add User Defined variables in the ID request also as shown below.

  • Now, save and run the thread group. Both the request will execute successfully as below.
  • 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.
  • Next, go to the JMeter and Disable the User Defined Variable.
  • 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.
  • 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.
  • Now save and execute the Request, after the execution if you check the Request body and response body you will find the details.
  • 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.
0 results
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions