Skip to main content

Featured

How to Visualize your JSON 🕵🏼?

A simple way to view and segregate the complex JSON Hello Peeps, Welcome back to another blog 😉. I hope everything is going well for you. Many people prefer the JSON format for APIs, databases, and other applications for a variety of reasons. Some JSON requests or responses are simple and only contain a few objects. On numerous occasions, you may be required to handle a complex response. I wrote a blog about parsing complex responses before using https://jsonpathfinder.com/ In most cases, however, you will need to further investigate your JSON payload or responses for various reasons and analytical purposes. Are you a visual learner or a fan of mind maps? Then you will undoubtedly fall in love with this tool ❤️ JSON Crack I recently came across this tool and found it’s worth sharing with the community 👓 Once you land on the home page, click “GO TO EDITOR” Now you will see a sample JSON beatified and visualized. To visualize it, clear the left side pane and paste your JSON. For in...

Smart Tests using Postman!!

 When you are planning to write Tests for an API, make sure to write it in a way where the dynamic variables are used wherever possible, because this will help you to cover new scenarios for every run.

Image for post

If you are executing a UI test case, for every run you want to test with dynamic or variety of values. Why?? Because you need to try breaking the application and find the hidden bugs. Sending a hardcoded number and directly writing the assertions to match the same with the API response is quite not a good test case I would say.

A good test case should always have less maintenance and more efficiency. I would like to explain an example here with a SOAP request, which details the steps and thought process which will help you to write smart tests using Postman. Yayyy!!

Why wait, let’s start.

For illustration purposes, am using the pubic SOAP API’s: https://documenter.getpostman.com/view/8854915/Szf26WHn?version=latest

Under the folder “Numbers”, navigate to the request “NumberToDollars”.So here, the input number is getting converted into words.

Step 1: Try to use dynamic variables instead of hardcoding the input.

Image for post

So I am using the dynamic variables which Postman offer by using {{$randomInt}}.

Image for post

Instead of using it directly inside the body, try assigning it to a variable (scope as per the preference) , by adding the below snippet to the “Pre-request Script” tab:

Image for post
Image for post

Step 2: Create a function to handle the conversion of the integer into words.

Here I am using some existing function code snippets, feel free to create your own functions based on the action performed by the API to get the end result, because you know exactly what your API does!

Step 3: The Dynamic variable can be passed as argument to the function we created.

We can see the value generated by this function. Since this is SOAP request below snippet also needs to be part of the code under Tests tab:

Step 4: Now we can write the Tests to check the actual value in the API response against the converted random variable using the created function for converting the number into words.

Here along with the conversion, the text “dollars” is getting appended to the last, so make sure to add that to the result which is generated from our function.

Image for post

After clicking “Send”,

Run 1:

Image for post

Run 2:

Image for post

Same approach is applicable for REST API’s as well.. This is just an example.

I hope you got the crux of this story. Make sure to use dynamic variables and try to avoid the hardcoding in the Tests whenever possible :-) Create your own functions, for repetitive tasks!! No harm in re-using the existing code snippets if it matches your requirement :-)

Comments