Execute postman collection with docker-compose

Reading Time: 3 minutes

Hello Everyone, Today we will go through with one interesting integration provided by Postman i.e run your collection using Docker. In this, we can see how we can integrate your postman API request and run it from a docker container.

Let’s start, the simple prerequisite for this blog is that you have docker installed in your machine.

What is Docker?

Docker is a container system in which you have all the dependencies that you required for the software to run is already pre-installed. In other words, it is a virtual machine that will have all the prerequisites that a developer requires to run a particular thing.

For example, right now what we required we must have a machine to have Node and Newman installed to run our postman collection in the command line. So, now we will use a Docker machine that already is having this kind of stuff and that we can just pass the URL of our postman collection, and it would directly run it and give us results.

So Docker is very helpful whenever we want to distribute our test cases or postman collection to certain people who are very new and they don’t know how to install certain dependencies.

Steps to run API collection using Docker

Let’s get started with the following steps-

  • First, we have to install Docker in our system.
sudo apt install docker.io
sudo docker -v
  • After that, we have to run the docker image. Postman has it’s own official Docker Image on Dockerhub with instructions to get you set up and started. It’s really simple to get your Postman collections running with the image, straight from the command line.
  • Run this command to pull the latest image. It will download the latest image from dockerhub and then your container will be setup.
sudo docker pull postman/newman
  • Now, you can easily run your particular collection from your docker container. Run this command for running you collection.
sudo docker run -t postman/newman run "Your-collection-link"
  • Create your new request in the collection, go to share collection and then you can copy “Your-collection-link” from clicking on ‘share collection’ and paste the URL of the collection.
sudo docker run -t postman/newman run "https://www.getpostman.com/collections/3233405da04e9fe4a8cc"
  • postman/newman is basically our container, and we are running our collection URL inside this container. so, let’s enter and we will see whether it is able to run our API Requests and the tests from this particular collection.
  • After running our command, we will see that our requests, test-scripts, iterations all passed and got the result in tabular format.

So, this is just a simple example of how you can run your API requests from a docker container. I hope this article will helpful for you.

References

https://hub.docker.com/r/postman/newman/


Knoldus-blog-footer-image

Written by 

I am Software Consultant - QA at Knoldus Inc. I have completed my B.Tech from Jodhpur Institute of Engineering and Technology. I am familiar with the core concepts of Manual and Automation Testing and tools such as Postman, Selenium, and Gatling. I am looking forward to roles that will help me realize my potential by exploring the various aspects of this field.

Discover more from Knoldus Blogs

Subscribe now to keep reading and get access to the full archive.

Continue reading