In my first article about J meter, I simply gave an introduction about JMeter tool. Basically we use JMeter for performance testing/load testing. This tool consists of lots of features and we can use those certain features according to our requirements. In my previous JMeter article, I just compared google and yahoo servers. We didn’t add more features. It was just a simple demonstration. But I think it’s good to get some more understanding about this tool.
In this article I will explain some more features about JMeter which I have learned recently. But if you already working with this tool, probably should know those features.
Well, Let’s think we have our business website with a login. We need to do some performance testing. Like we have done last time, run the JMeter using the terminal.
User defined variables
Initially you can add user defined variables. eg: host, port, scheme, agent. When you define those variables, it’s easy to use for the requests. Because you can just use the variable there instead of adding the details every time when you send the requests.
Http cookie manager
Then better you add a cookie manager. (Test plan→ config element → Http cookie manager). If there are cookies in request and responses, the cookie manager stores those cookies and will use them for future requests.
Then create a thread group and enter the thread properties. I think you know how to do it. Check my previous JMeter article if you need to know more about it. Based on your requirements, you can add the thread group properties.
I mentioned above we have a login for the website. So simply what the user is doing? Enter username and password and then login. So what the Jmeter is doing here?
CSV data set config
Before adding the https/login request, we can add a CSV data file including our login credentials. Add your username and password values list in a sheet and save it as a CSV file. All good! Now we can attach that file into JMeter. But how?
Add a CSV data set config file. Use the below flow.
Thread group → Config element → CSV data set config
In the file section, attach the relevant CSV file. Don’t forget to put variable names. Keep the rest of the fields with default values. But if you want, you can change it based on your requirements.
Now we can add our request. I already described that in my previous JMeter article.
(Thread group → Sampler → Http request)
I named it “login”. As you remember, we added user define variables. So to fill up this, we can use those variables. You have to use the below format when adding.
For the path, here I should give the login path. You can get these data from your API documents. For body data, use the same variables that you have added in the CSV data set config file. I think I don’t need to explain about request types. Here we are sending credentials and trying to login to the system. So we use POST request type. Because we POST variables.
Http header manager
When we send the API requests, we send relevant headers with them. Those headers represent the meta-data associated with requests. If you have worked with the Postman tool, you should have a good idea about headers. You can view header details in your API document. There are different types of header names and values.
Normally when we send a login request, it creates an access token if the credentials are true. So we can use that access token for next requests we send. To store that variable, we use the JSON extractor in JMeter.
(Login request → Post processors → JSON extractor)
To access the token, we have to add the path expression as follows. Check the below image.
Response assertion and assertion results
Another feature is response assertion. You can use this feature to verify whether the response includes certain patterns/codes. As an example, you need to check whether the response has code 200. You must set the settings as follows.
So if the response doesn’t have 200, the test will fail. You can add “Assertion results” (Listener → Assertion results) and see its results separately. It’s a kind of view results method. That’s how response assertion works.
View results tree and summary reports
There are a number of ways we can view the results. I”ll explain 2 ways here.
1.View results tree (Login → listener → View results tree)
You can view all the requests one by one. When you click a request, you can view all the request and response data, body everything in detail.
2.Summary report (Login → Listener → Summary report)
Here you can get all the requests and results as a complete summary.
Number of samples, error rate, throughput value etc. From these values, you can measure the performance level of your application.
So I think you learned some new things about JMeter. This tool has more features. Hope to write another chapter when I go through them.