Javatpoint Logo
Javatpoint Logo

JMeter Web service API Test Plan

Before proceeding with this section, let us first understand some of the key concepts regarding Web Services API.

Web Services

Web services are defined as a software system designed to support interaction between two machines over a network. It is designed to have an interface that is depicted in a machine-processable format usually specified in Web Service Description Language (WSDL). Typically, "HTTP" is the most commonly used protocol for communication. Web service also uses SOAP, REST, and XML-RPC as a means of communication.

A Web service might not contain a complete set of specifications and sometimes might not be able to perform all the tasks that may be possible from a complete API.

API (Application Programming Interface)

An API acts as an interface between two different applications so that they can communicate with each other. It is a method by which the third-party vendors can write programs that interface easily with other programs.API may use any means of communication to initiate interaction between applications. For example, the system calls are invoked using interrupts by the Linux kernel API.

An API consists of a complete set of rules and specifications for a software program to follow in order to facilitate interaction.

Web API

A Web API can be considered as a development in web services where emphasis has been moving to simpler representational state transfer (REST) based communications. Restful APIs do not require XML-based web service protocols (SOAP and WSDL) to support their interfaces.

Web services are broadly classified in two categories:

  • Simple Object Access Protocol (SOAP)
  • Representational State Transfer (REST)

For our test purpose we will be using some publically available REST API's to test with JMeter.

You can search for various publically available REST API?S on the internet and get the API key to set up a test in JMeter. You can also build an entire Web Service Project using any development environment and deploy it on JMeter to run a test plan.

For this test, we are using API provided by Open Weather Map website under the URL:

https://openweathermap.org/api

The following image shows the API section provided by Open Weather Map website.


JMeter Web service API Test Plan

You can sign-up on this website to get access to your API key which is subsequently used to get the proper weather reports.

In our case, we have generated our API key as: 3f25ec8eed9e1951e21407a34312c2c8

The following image shows the generated API key after successful login.


JMeter Web service API Test Plan

Now, we will use this API key along with the method to call API to get the desired results. The method to call an API includes the server name followed by the city code/city name and API key.

The following image shows an example of an API call provided by OpenWeatherMap website.


JMeter Web service API Test Plan

Now, we will create a Test Plan to test REST API provided by the OpenWeatherMap website.

Create JMeter Test Plan

  • Go to your JMeter bin folder and double click on the ApacheJMeter.jar file to launch JMeter interface.
  • Click on the Test Plan node.
  • Rename this test plan node as WebServiceTest.
  • Select the WebServiceTest node and right click on the selected item.
  • Mouse hover on "Add" option, then elements list will be displayed.
  • Select Threads (Users) > Thread Group.

Modify the following properties of the thread group:

  • Name - Webservice user
  • Number of Threads (Users)- 2
  • Ramp-Up Period - leave the default value (1).
  • Loop Count- 1

JMeter Web service API Test Plan

Add Sampler

  • Select the Webservice user element (Thread Group) and right click on the selected item.
  • Mouse hover on "Add" option, then elements list will be displayed.
  • Select Sampler > HTTP Request.

JMeter Web service API Test Plan

Set up the following fields in the HTTP Request control panel:

  • Name - HTTP Request
  • Server Name or IP - api.openweathermap.org
  • Path - data/2.5/weather
  • arameters - q = London
  • appid = 3f25ec8eed9e1951e21407a34312c2c8


JMeter Web service API Test Plan

Add Listener

The Listener element will be responsible for storing all of the results of your HTTP request in a file and presenting a visual model of the data.

  • Select the Webservice userelement.
  • Mouse hover on "Add" option, then elements list will be displayed.
  • Select Listener > View Results Tree option.

JMeter Web service API Test Plan

Save and Execute Test Plan

  • Click on File > Save Test Plan as.
  • Save the entire test plan as HTTP_test.jmx.

  • JMeter Web service API Test Plan
  • Click on Run > Start to execute the test plan.

Verify the Output

The following output can be seen in the listener.


JMeter Web service API Test Plan

JMeter Web service API Test Plan

In the Response data tab, you can see the actual weather report provided by OpenWeatherMap website.


JMeter Web service API Test Plan




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


B.Tech / MCA