Sitemap

Postman for automated testing api’s — Intro

6 min readOct 20, 2020

Recently my team and I were discussing ways to speed up code reviews. Thats when Postman pop into my mind. With expected return values agreed upon, it’s much easier to test if api’s are working as they should. So when the senior dev needs to do code review he just needs to go through the checklist.

Press enter or click to view image in full size

Lets get right into it. I need to test my backend api without using the ui.

Press enter or click to view image in full size

So in-order to do that I open up google chrome developer tools & goto Network tab

Press enter or click to view image in full size

I want to create a single contact so I need to watch the network to see what api request is being made.

Press enter or click to view image in full size

create lead list

Press enter or click to view image in full size

We see in the network tab: Request URL: http://localhost:1337/api/lead-list
and down below Request Payload

Let open up Postman now
2 steps: Change to POST & enter in URL: http://localhost:1337/api/lead-listf

Press enter or click to view image in full size

Now for my api we require a token in the header

Press enter or click to view image in full size

Add that to Postman

Press enter or click to view image in full size

Now we to add the body: first get the Request Payload, click the view source then copy the Payload.

Now prepare finish our postman body

Press enter or click to view image in full size

When I click Send I get an error

Press enter or click to view image in full size

Because we created test 1 sms with the ui in-order to get the information for postman. So lets delete test 1 sms

Press enter or click to view image in full size

Then send with postman again and we have a successful Lead List created

Press enter or click to view image in full size

Just for show I changed the name to test 2 sms

Press enter or click to view image in full size

In our Ui we see our created list names

Press enter or click to view image in full size

Lets add a contact to the list. We will start by adding a single contact

Press enter or click to view image in full size

I add my number and click create

Press enter or click to view image in full size

Here is the network request

and the payload

Press enter or click to view image in full size

We need to add this to Postman. In postman we need to create a new tab but an easier way is to duplicate the first tab

Press enter or click to view image in full size

So after setting it up and send

Press enter or click to view image in full size

There is one thing here we can automate and thats the lead_list_id

In the first post we received a response with id

Press enter or click to view image in full size

Lets grab that response id and save it to a global variable

For goto the first tab created and click the tests tab. Here I pre-wrote some javaScript to get the json response and save it to a global variable id

Press enter or click to view image in full size

After changing the Body to {“name”:”test 3 sms”} and running Send. The console shows us the json response.

Press enter or click to view image in full size
Press enter or click to view image in full size

Now go into the second tab and change lead_list_id value to “{{id}}” this id was set earlier as our global variable carrying the value: 5f8e711bdf4f8b003863adfa

Press enter or click to view image in full size

So now we learned to take responses and set data into globals variables.

Next I want to automate sending of messages.

Press enter or click to view image in full size

After filling out Campaign Name and To and Message there were network calls. We need to take those network calls and paste them into Postman like we did earlier.

Press enter or click to view image in full size

Goto Postman and Duplicate a tab

Press enter or click to view image in full size

Setup a POST Request

Press enter or click to view image in full size

On Send we get a response of campaign id

Press enter or click to view image in full size

We need to put campaign_id into a global variable and run it. This will but get the response campaign_id then put it into the global variable campaign_id.

Press enter or click to view image in full size

Grab our next Request

Press enter or click to view image in full size

Postman: Duplicate another tab

Press enter or click to view image in full size

Add our global variables campaign_id & id to the Request URL and id:

Press enter or click to view image in full size

On to the next Request

Press enter or click to view image in full size

Duplicate a tab and add the Request URL and body. We add our global variable id in the URL itself {{messageid}}

Press enter or click to view image in full size

Finally we capture the network call on Send. This is what we get

Press enter or click to view image in full size

Setup our last tab on Postman. url with empty body

Press enter or click to view image in full size

Lets test it all out. Lets save our test api’s

Press enter or click to view image in full size

Create a collection

Press enter or click to view image in full size

Save them in the order they were created and Click Runner

Press enter or click to view image in full size

Click the test api collection

Press enter or click to view image in full size

unclick the first 2 requests

Press enter or click to view image in full size

Click Run test api and see the results. All green status 200

Press enter or click to view image in full size

Will that was the basics of using Postman. I hope you learned something. Cheers.

--

--

Kafka
Kafka

Written by Kafka

“Genius” is 1% inspiration and 99% perspiration. Accordingly, a ‘genius’ is often merely a talented person who has done all of his homework — T.E.

No responses yet