Step by step load test with JMeter-part 2

Calling POST API

Add another HTTP request. Right-click on Thread Group and go to
Add > Sampler > HTTP Request

Set following configuration:

protocol[http]: https
Server Name or IP: customer-test-api.herokuapp.com
Port Number: 443
Method: POST
Path: /customer/api/v1/login

Now, go to Body Data tab and write following JSON script and hit ctrl+s to save the configuration.

{
    "username":"salman",
    "password":"salman1234"
}

Add HTTP Header Manager

Then right-click on Thread Group and go to Add > Config Element > HTTP Header Manager

After adding this, select it. Then add following configuration:

Name: Content-Type
Value: application/json

Now Set the Thread 1 and Ramp up period 1 from Thread Group

Then, disable previous HTTP Request as that is currently not needed. When needs this, enable that and disable the others.

To disable a request, right click on the request and click on Disable

Now, click on play button

Select “View Results Tree”

You will see that request has been executed and in the response tab, you will find a response that contains a token.

Extract Data from JSON response:

Now we will extract token from the response.

Right click on Thread Group and go to Add > Post Processors > JSON Extractor

Then add following configuration:
variable name: token
JSON Path Expression: $.token

It means, token will be extracted and set to “token” variable

Already done. Now we will call a GET API that needed authorization.

In our first HTTP request (part 1), we had no authorization. But now we will call a GET API which needs to add authorization in its header

Configure header authorization

Select HTTP Header Manager.

Click on Add button

Add following configuration:
Name: Authorization
Value: ${token}

In the previous section, we have set the JSON variable name as “token” which contains our generated token. So while reading the token value from the token variable, we have to use this syntax ${token}

Now add another HTTP Request and set following configuration:

protocol[http]: https
Server Name or IP: customer-test-api.herokuapp.com
Port Number: 443
Method: GET
Path: /customer/api/v1/list

Now click on play button

Select “View Results Tree”

Select second HTTP request as this is our current request, go to Response data tab

You will see that response is showing

about author

admin

salmansrabon@gmail.com

If you like my post or If you have any queries, do not hesitate to leave a comment.

Leave a Reply

Your email address will not be published. Required fields are marked *