API Testing bằng Postman – Collection runner

Tram Ho

Back to the “API Testing with Postman” series, we learned how to make a request on Postman, write test scripts for test cases and finally add them to the collection to create tests. suite Today we will continue with how to run Postman as an automation test tool with Collection Runner and Newman tools.

1. How to create Collection Runner

There are two ways to run a Postman collection: Collection Runner and Newman, start running a collection with Collection Runner

Step 1) Click the Runner button on the top left corner next to the Import button

Step 2) The Collection Runner page will appear as shown below

Description of fields:

  1. Select collections here. If you have sub-folders you will need to select that subfolder
  2. Don’t forget to select the environment if you have a special environment
  3. Select the number of times you want to repeat
  4. Select the amount of time to wait to avoid an error
  5. The state of logging the responses
  6. If you use data file, select here

Step 3) Run the User Test Collection by setting up the following

  • Select User Test Collection – Select repeat 3 times
  • Choose a standby time of 2500ms
  • Click Run User Test Collection

Step 4) Run and the Results page will display after you click Run button. Depending on the timeout, you will see the test cases running

  1. Each completed test case, you will see the test status is Passed or Failed and the result of each iteration
  2. You see the Pass status for Get Requests
  3. Since we have not written a test case for Post Request yet, there will be a message saying “This request does not have any tests”.

Here, you can see the test in your request, can check if the HTTP request has been successful and whether the data has been created or returned.

2. How to run Collection using Newman

Another way to run the collection is through Newman. The differences between Newman and Collection Runner are:

  1. Newman is an add-on of Postman. You will need to install it separately from the Native App
  2. Newman uses the command line while Collection Runner has GUI
  3. Newman can be used for continuous integration

To install Newman and run your collection from there, follow these instructions:

Step 1) Install nodejs with the following link:

Step 2) Open the command line and enter

Newman will be installed to your computer as follows

Step 3) When Newman is installed, or return to the Postman workspace. In the Collections box, click on the “…” sign. A popup will appear. Select Export

Step 4) Select Export Collection as Collection v2.1 (recommended) then click Export

Step 5) Choose where you want to save and click Save. It is advisable to create a special folder for Postman test cases. A collection will be exported if you select a folder

Step 6) We will need to export the environment. Click on the eye icon next to the environment dropdown in Global, select Download as JSON. Choose a destination and click Save.

Step 7) Environment should be exported in the same folder as Collection

Step 8) Now go back to the command line and change to the folder where you saved the collection and environment

Step 9) Run your collection with the following command

The result after running will appear as below

Reference to some basic commands of Newman

  • Running a collection This statement is used if there is no environment or test dependent data

  • Running a collection and environment adds the -e parameter

  • Run a collection with repetitions

  • Run with data file

  • Running with timeout. This is important in a test that can fail if there is no waiting time between requests

3. Summary

  • Postman is the most popular tool currently used for API Testing
  • Flexibility, use of collections, collaboration, Continuous Integration, are the best features when learning about Postman
  • Encourage access to the Postman account and your collection will be pushed to the cloud
  • You can parameterize the request in Postman
  • You can create testcase to verify the request
  • Collection can be run by Newman or Collection Runner

Refer

Share the news now

Source : Viblo