Application Programming Interface (API) allows one software to interact with other software. It is a messenger that takes a request from one system to another system, provides the requirements and gets the response back to the requesting system.
Why Choose Apache JMeter for API Testing?
Some of the prominent reasons as to why Apache JMeter is used for API Testing are:
- Open-source tool – The Apache JMeter is an open-source tool based on Java used to perform load testing and performance testing.
- Cross-platform testing – Since JMeter is solely Java-based, it can be used on any platform that has a JVM; Windows, Linux, or macOS.
- Smooth API Testing – API Testing enables easy, smooth, and rapid API testing.
- Quick scope tests – JMeter is a potent tool for performance testing, making the process easy for everyone, whether experienced or inexperienced.
- Enables load testing – JMeter is a very effective tool to measure if a web application satisfies a particular load requirement or not.
- Enables stress testing – JMeter can simulate users to measure the application performance under a lot of stress.
- Lots of plugins – JMeter offers a lot of plugins, and more plugins can be installed easily by installing a Plugins Manager.
Proposed POC contribution:
I learnt using JMeter for Performance Testing and the very first target were the APIs, cause we want to understand its performance when in load. However, since this was a POC, we weren’t able to test it against enough load and began with the SANDBOX environment.
I am going to further explain the processes, elements, listeners and assertions I’ve implemented in this Registration flow script:
Script has been implemented for the following APIs:
Features used and how:
1. User Parameter
1. User Parameter
User Parameters are used to define values for the variables before they are used in the Samplers. When JMeter executes this Pre-Processor element, it stores the values in the variables which can be referenced by any Samplers within the same thread group. If you have more threads than the number of users in “User Parameters” then extra threads will re-iterate through the values again.
To generate a random string to concatenate in “emailid” value, which is needed during Registration.
- Response Assertion
The response assertion lets you add pattern strings to be compared against various fields of the server response.
- Duration Assertion
The Duration Assertion tests that each server response was received within a given amount of time. Any response that takes longer than the given number of milliseconds (specified by the user) is marked as a failed response.
3. Regular Expression Extractor
It is a post-processor and is useful for extracting information from the response.
I’ve used this post-processor in extracting guest access tokens, member login from the guest access token and used it in the necessary HTTP requests.
The listener allows us to view and analyze the Sampler request and response in the form of tables, graphs, trees etc. You can also save results in a file and read saved results later. You can access the sampler result in an ongoing load/stress test without waiting till the end. A listener can be added anywhere in the test plan. It will gather data only from elements defined in its scope.
- Assertion Results:
Assertion Results display the results of assertions applied on the Sampler.
- View Results in Table:
View Results in a table creates and displays a row for every sample/request result separately.
- View Results in Tree:
View Results Tree displays a tree consisting of all the Sampler responses along with their requests.
5. Config Elements
- HTTP Request Defaults:
HTTP Request Defaults Configuration Element lets us set default values to be used in other HTTP Request Samplers.
Defining sandbox ww4 as a server
- HTTP Header Manager:
This contains and maintains the HTTP headers that are sent to the server from the browser in use for sending the request and getting the response.
I believe this post could help someone trying to begin with Performance testing using JMeter. There are many more Assertions, Listener, Config Elements, etc. that can be explored as we broaden our targeted samples.
That’s all folks 😀