How To Use Counter In JMeter

Posted By : Palak Tiwari | 31-Jan-2018

For better understanding here, lets take an example of test data generation using JMeter. For that, we will register multiple users by incrementing a username (Eg. user+1, user+2, user+3 and so on). This is a very simple example of test data creation. And it can be automated using JMeter Counter. Lets  see how  we can do  this:

With Jmeter counter:-

The screenshot shows parameters used in HTTP Request.Our Request will be sent in JSON format, So Now we have selected Body Data option here.

*Here we  will change ‘username’ value in above request to ‘user+1’, ‘user+2’ etc for multiple number of users creation.Here JMeter Counter comes in to the picture. Jmeter allows us to increment a value.We can add JMeter Counter in our  script by:
(a) click on Thread Group and then select Add–>Config Element–>Counter option.

*Below screenshot will give you idea about Counter element. Since we are starting from value 1 and then increment that value by 1, we have set Start and Increment values by 1 accordingly. Now Set Reference Name value to ‘userCount’ now we will use this in our JSON request.

 


After  the  counter setup now, we need to update our JSON request with a counter reference name (userCount in our case). Below screenshot shows how we can do it

As we have our setup ready, we can run our script for many users and then our users created with sequential numbers.

This example of JMeter Counter shows test data creation.


What can we do with JMeter?

It is used to test performance both on static and dynamic resources such as static files, Java Servlets, CGI scripts, Java objects, databases, FTP servers and more. JMeter basically used to put a heavy load on a server, network or object to test its strength or we want to analyze overall performance on different load types. JMeter is compatiable on any environment/platform such as Windows, Linux, Mac, etc. Jmeter is used to perform automated and functional testing.

THANKS

Related Tags

About Author

Author Image
Palak Tiwari

Software tester with good knowledge testing skills in various areas. She believes in continuous learning .

Request for Proposal

Name is required

Comment is required

Sending message..