Using Postman to Test API Calls

As automation systems become more connected, it’s increasingly necessary to utilize different tools to test your applications. Fortunately, there are plenty to choose from. Postman is an API platform for building and using APIs, and is an extremely useful tool for testing any call that your SCADA system uses, including any API’s you’ve created in your SCADA system. While it’s great for testing out individual API’s using the generic GET, PUT, POST, and DELETE calls, the real power comes from using Collections inside of Postman and automating the tests as much as possible.

Below is a walkthrough of some of the systems we put in place to test out every API endpoint inside of Locera. Although Locera is a traditional software system and not a SCADA system, the same principles can be applied to test your SCADA projects, along with any software projects you are building or have already built.

Step 1: Create your Workspace

First thing first after downloading Postman, get your account set up and create a workspace to store all of your Collections and tests.

Step 2: Create your Environments

After you have a Workspace setup you’ll want to create as many environments as you need to test. Here I have a Dev, a Test, and an implied Prod. Here you will also want to set any Variables you may want available through the tests. I just use placeholders as I will change them programmatically later.

Postman Workspace Creation Page

Step 3: Create Collection and Assign Pre-request Scripts if Needed

Now that your environments are set up, go to the collections tab and click the plus button to create your first Collection. Once the collection is established, click on the item you just created to start working with Pre-Request Scripts. A Pre-Request Script allows you to define a set of logic that will call before each request. In this case, it logs a user in and stores the result as an environment variable. When you see the code pm.variables.set this is setting an environment variable for you to have access to anywhere else in the collection. These can be accessed either through code with the pm.variables.get script or with {{variable name}} in non script parts of Postman. Because Locera uses Authentication and Authorization, you need a way to login a user to make subsequent API calls, this can be accomplished with a Pre-Request Script.

Step 4: Create Request

Now it’s time to create your request. Simply choose the request type, enter the URL, environment variables, and assign any headers needed.

Step 5: Write Tests

Postman has a great selection of snippets that can be used to start testing. Some of the basic tests that can be written are: verify status codes, verify values, and validate return schema.

Step 6: Run Tests

Click the top level of your Collection folder and press the Run button. This will run every test in the collection all at once, thus automating a little bit of your testing process.

Summary

With Postman, we’ve been able to automate parts of our API testing to streamline the validation of Locera’s calls. Hopefully this quick step by step helps with your projects and prevents some unnecessary bug-squashin’ in the future.

Leave a Comment

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

Scroll to Top