Step by step load test with JMeter-part 4

Register new customer

Add a new simple controller. Right click on it and add new HTTP Request.

Edit the HTTP Request name to Create New Customer

Then set following configuration:

protocol[http]: https
Server Name or IP: ${baseUrl}
Port Number: 443
Method: POST
Path: /customer/api/v1/create

Then click on Body Data and add this script:

    "id": ${id},
    "name": "${name}",
    "email": "${email}",
    "address": "Dhaka,Bangladesh",

Then ctrl+s to save the configuration

After saving the configuration, HTTP Request name will be changed to your given name

Generate Random Number

Now right click on Simple controller and click on Add > Config Element> Random Variables

Drag and move the Random Variable before the Create Customer HTTP Request

Then add following configuration:

You can set minimum and maximum anything as your wish

We moved the Random variable before the “create new customer” HTTP Request so that we can generate the ID before and use it while creating new customers.

JR223 PreProcessor

JR223 PreProcessor is used to do something before sending a HTTP Request.
The reason for adding pre-processor is to generate some random values and create different customers.

Right click on the simple controller and click on Add > Pre Processors > JR223 PreProcessor

Drag and move it to before “Create New Customer” HTTP Request

Now add the following groovy codes. PreProcessor by default supports groovy code. Also, you can use Java or JavaScript

import org.apache.http.client.methods.HttpGet
import org.apache.http.impl.client.HttpClientBuilder
import org.apache.http.util.EntityUtils
import groovy.json.JsonSlurper'----- Calling user info generating API -----')
def httpClient = HttpClientBuilder.create().build()
def httpGet = new HttpGet("")
def httpResponse = httpClient.execute(httpGet)
def responseData = EntityUtils.toString(httpResponse.getEntity())'----- Response -----')

slurperresponse = new JsonSlurper().parseText(responseData)'----- Set to environment variables-----')

Now ctrl+s to save the script. Then clear the previous history and run the project

You will see that new customer has been created through the API

Now go to the Request tab. You will see every time will generate new info for the customers.

Then move the “view Results Tree” at the last. So that it beautifies our project.

Beanshell post-processor

Beanshell post-processor is used to do something after getting the response. In this segment, we will save our response in a CSV file

Right click on Simple Controller and click on Add > Post Processors > Bean Shell PostProcessor

Add following codes:


FileWriter writer = null;
String location = "mycustomers.csv";"=============Started wrting Data to CSV file=======");

try {
	writer = new FileWriter(location, true);

	String id = vars.get("id");
	String name = vars.get("name");
	String email = vars.get("email");
	String phone_number = vars.get("phone_number");
	writer.append('\n');" "+name+" "+email+" "+address+" "+phone_number);"CSV file is created...");

} catch (IOException e) {


Now save and run the project for 3/4 or multiple times

You will see “mycustomers.csv” file has been generated in the bin folder

Open the file. you will see every customer record has been stored in the CSV file

about author


If you like my post or If you have any queries, do not hesitate to leave a comment.

Leave a Reply

Your email address will not be published. Required fields are marked *