Summary Guide for Creating and Maintaining Automated API Tests

API stands for Application I nterface. It’s a set rules that allows programs to communicate with each other. APIs allow server-client communication to be made easier.

defines the API’s appearance. It stands for REpresentational Transfer. This is a set rules developers must follow when creating their API. One of these rules is that you must be able get data (called a resource), when you link to a particular URL.

Each URL is a Request, while the data you receive back is a Respond.

These are the Request methods.

  • GET is used to access a resource
  • POST – Used to create information
  • PUT – Used to update a resource
  • DELETE – Used to delete a resource

The following resources will help you learn more about APIs:

  1. This PPT helps you understand APIs better.
  2. REST APIs can be a powerful way of running tests. Offers an Addon to RESTful API Testing capabilities. Used as a functional testing platform by the API Addon. It combines API steps with functional UI automation to make testing more powerful. The RESTful API addon allows you to send HTTP/S request using POST, PUT, and DELETE methods. It is free, and you can modify it to meet your needs.
  3. For an API Testing Glossary check out this List of Definitions by Dave Westerveld.
  4. Prashant Hedge also wrote an instructional tutorial on mastering API Test Automation in 10 minutes that you should absolutely check out!

Note: This tutorial was submitted as part the Master Program. I invite everyone to participate, get involved in the community, and receive really cool certificates and gifts!

Learn How to Automate REST API Testing

List APIs for automating tests





Definitions for the above APIs can be found here:

You must first list the user flows that need to be automated. The scenario that we will automate in our case is:

  1. Validate the first employee’s name and get full employee list [This is optional for our user flow. It is just an added bonus.
  2. Register a new employee and verify it.
  3. Validate the changes made to the employee record.
  4. Verify that all changes have been reflected in your employee record.
  5. Validate the employee record by deleting it.
  6. Verify that the employee has been removed from your records.

Writing Tests

Once you have specified the URL and selected the method, we can create a test-script to validate our response code and response data.

This example will include scripts to validate the request response code and verify the employee name in the first“Status code is 200”, function (); );pm.test(“Check First Employee name”, function () { var jsonData = pm.response.json(); for(var i=0; i This is what our first postman test looks like.

Click on to check the results of our test. The TestResults section will display the status of the test. You can change the expected code value to something other than 200 and then check the result. Failed, right?

Now that you’ve seen how to create a test to validate your request, let’s move to automation! Testing several API requests one by one can become a repetitive and tiring task, hence we need to automate our API tests.

Create an API Collection

A collection is where all API calls are placed. Once you have created the environment, click again on New >> Collectiongive it a name and a description (Optional). Then click on create

Once you have done this, you can import files, folders, links, or the JSON Raw Text. We will use the following collection for testing purposes:

This collection already contains some API request tests that we can map to the scenarios discussed in ” . The scenario we will automate issection . After the automated tests are defined in each request, and all requests have been prepared, we will use Run to make all calls simultaneously. As you can see, six calls will be displayed in our request if they were imported correctly.

Next, click on ” Run“. This will open a new window. Next, select the collection you wish to execute (collection imported in previous steps), choose the Environment that was created before and the number of Iterations. Finally, click on RUN. This is the PostmanRunner Window.

The final screen displays the results of each execution, along with the test that passed or failed. You can also run the tests again, create a new test or export your results. The image below shows Postman’s execution results:

Running the Collection via Command Prompt using Newman Plugin

Let’s move on to Newman, if you plan to use your tests with continuous integration tools, such as Jenkins. Newman is similar to Postman, but it is run from the command line. This means that you can run your tests via and npm commands.

To export your collection, select Collection v2 then click on Export. Give a short name so that you don’t have to type a long name. The JSON file will contain all items from the selected collection. You can also download the Manage Environment popup.

Open terminal, and then use the following command to install install -g newman. Next, navigate to the location that the JSON (collection file) is saved.

Enter the following command to execute: newman run employee_data.json. -e demo_data.jsonIn where “employee_data.json” is the collection and “demo-data.json” is the environment JSON previously downloaded.

On executing the command, all the test results, including the number used in iterations, requests made, and test scripts, will be displayed at the terminal.

You can also export your results to html, for this we need to install “newman-reporter-html”, and execute “newman run employee_data.json -e demo-data.json -r html” which will generate HTML report in the same folder where the collection is exported inside a folder called newman.

Summarizing Guide for Creating and Maintaining automated API tests

This is just basics so expect more to come in upcoming articles… 🤯
I’d like to conclude this REST API Testing tutorial with the following flowchart I’ve made to help you create and maintain your automates API testing efforts:

Leave a Reply

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