• Home
  • /
  • API Testing with Postman (Part I)

API Testing with Postman (Part I)

What is API testing

API stands for Application Programming Interface. It enables communication and data exchange between two separate software systems. A software system implementing an API contains functions/sub-routines which can be executed by another software system. This testing is carried out in Business Logic layer. API Testing requires an application to interact with API.

It is Postman + Newman + Jenkins

Why Postman is selected

Postman is a powerful GUI platform which makes API development faster and easier, from building API requests through testing, documentation and sharing. It is available as a native app for Mac, Windows and Linux operating systems. Test cases can be easily written using Java Script.

Further Integration

Test cases can be written using postman. Set of test cases can be executed as a collection. That collection can be exported. Using Newman, the collection can be run. Having set a postman account, the collection can be shared. Having installed node and Newman, the collection can be called through URL and executed in command line. In addition to that, it is expected to integrate SVN with Jenkins. Therefore, whenever a code change occurs, it will be tracked and executed the scripts. The test report will be emailed to selected email recipients.

Writing test cases with Postman 

Postman Installation

Postman can be downloaded and installed from here. https://www.getpostman.com/

Start writing test cases

Follow the below steps to create test suite and test cases.

1. Create a collectionTest cases are written in Java Script. This is an example of a one test case.

 

tests [“Status code is 200”] = responseCode.code === 200;

This is how the whole response is passing to a variable.

var jsonData = JSON.parse(responseBody);

console.log(“keycount1: “+keycount1+” “+Object.keys(jsonData));

console.log(“keycount2: “+keycount2+” “+Object.keys(jsonData.result));

2. Create a folder under a collection

 

3. Go to Tests tab. Test cases should be written there. Enter request URL in shown tab. Select request type.

4. Save it, give a valid name and select relevant collection and folder.

5. Start scripting. Boilerplate codes can be found in the right corner. You can use them and customize. It’s all about Java Script.

6. After a test case is done, click on ‘Send’ button. The pass/fail count is displayed below. A bunch of test cases can run on one click.

7. Run the collection.

8. Then the collection runner will open.

9. Click on ‘Start Run’ button. After running the whole collection, the test results will be displayed with a detailed report. The test result can be exported as well.

(To be continued with how it is integrating with Newman and Jenkins)