API Testing through JMeter

In my previous post, we understood how to set up JMeter. I also shared a brief about how we perform API testing using Jmeter. In case you missed my previous tutorial. Visit Introduction to JMeter and Environment setup

Till now I have come across a hell lot of blogs, tutorials that convey JMeter’s impressive capabilities as performance and load testing tool, however, seldom do I see folks sharing their experience with JMeter for API testing and Web Application testing (Web Driver + JMeter).

We have all heard of SOAPUI  which is considered as one of the best tools for API testing, but after having used both, I can say I am much happier with Jmeter as it is FLEXIBLE to the core and off-course it is Free 🙂

What is an API?

API stands for Application Programming Interface. It is used to interact with external entities which interact (Request and Response) with our application. Below diagram would clarify.

JMeter architecture

My Application” in above picture interacts with all the external entities using APIs. It is dependent on these objects for various things like Validation/Verification of some data conversion of some data etc.

API can be written in  REST or SOAP Protocols / XML or JSON formats.

An example of XML/SOAP API Request.

<?xml version="1.0" encoding="UTF-8"?>

<req ver="1.0">

	<a></a>

	<b></b>

	<c></c>

	<d></d>

	<e ></e>

	<f ></f>

</req>

a,b,c,d,e,f:- These are the parameters which we send in a request, these are values like session,language,amount,authentication etc.  In-Short this is how you create your request that needs to be sent to an external entity.

e.g. :- <amount>100</amount>

An example of JSON/REST API Request:

{

"a":"",

"b":"",

"c":"",

"d":"",

"e":"",

"f":"",

"g":"",

"h":""

}

e.g. – “Amount”:”100″

Similarly, for this JSON request, the parameters are to be defined in the above manner.

I will share a complete JMX in the coming lessons.

Please note that we will not be sharing basic details about Jmeter like Thread group, Samplers, Controllers, and Assertions, etc. These are best explained on:-

http://jmeter.apache.org/usermanual/

Please refer this user manual link for detailed explanations of what are the capabilities of JMeter, & we will tell you how to do it 🙂

Let us create an API request for paying off bill below.

  • Open Jmeter.bat on the path JMETER\apache-jmeter-2.13\bin. The below screen opens up.

Testplan

You can see the Test Plan; You can rename it, put some comments, check the boxes mentioned. Their functionality is best understood on the link listed above.

  • Create Thread Group. You can rename it, add users, set the execution time, etc.

3

  • Add a Sampler. What kind of request you want to create. Here, we are creating a SOAP Request in XML format. Again it can be renamed to a more sensible name as per your test.

4

  • How to tell JMeter which IP/Port to hit?? Add it to the URL. Example:                          
    https://${IP}:${Port}/${ContextPath}${AnyHeaders}

 

  • Creating Request. Add the request you created earlier in the open space as shown below.

6

  • How do you see the result of the request sent? Add a Listener.

7

  • To execute, click the green Play button. You have sent your request on the server:port where the code is deployed which in turn will hit the external entity.
  • How to check the Results? You will click on the listener which you added. I have added a TREE. As you can see, there are three tabs. Sampler result gives you overall data of the execution.

Click Request it tells what the request was sent

Click Response it shows the response received.

Please note that in the below screenshot, I was having some trouble connecting, hence the error.

That’s it, folks. This is how you test a SOAP/XML API for its functionality.

You can change the values of the request to check if the validations have been put by the developer like amount can`t be negative etc.

I would suggest you to open the logs (on Linux/windows etc..) and open continues logs when you hit the request. It would tell you what request has hit the server. What is the functional flow of the code?

Let me know if you face any issues while creating this. In the next article, I will share how to do it for JSON/Rest APIs.

For any Questions, Queries or Comments, Feel free to write ua at nilesh@qatechhub.com or support@qatechhub.com

 

Saurabh Dhingra

About the Author

Saurabh Dhingra

Follow Saurabh Dhingra: