This is the last blog in my small blog series about using Postman for API testing.
You can find the other blogs here:
- Using Postman for Odata development
- Using environment and variables in Postman [Since DJ Adams have already covered environment and variables in this blog. I won’t repeat his.]
- How to record http requests to be used in Postman
- Using Postman collections in your CI
In this last blog we will look into using the requests you’ve collected using postman and export them from postman to be used in a potential CI process.
I’m using the tool called Newman which can be grabbed from NPM.
So first thing you need is to make sure you have Node.JS installed on your computer.
Now open your terminal or command prompt and write the following command.
npm install -g newman
This will install newman in a global manner on your pc to be used and referenced from anywhere.
Ok, go into postman and export your collection by clicking the … icon on the collection and choose export. Use the v2 version.
When you’ve done the export use the terminal / Command prompt to navigate to your folder where you stored the JSON file.
Now write the command newman run <Name of your collection file>
In my case it’s
newman run ./Blog.postman_collection
as I’ve named my collection Blog.
You will see a series of requests coming from your command line and lastly a summary of whether everything went as planned.
If you want to use this method to create testdata, you can use the option -n and the number of times you want to reexecute the same collection. For example
newman run ./Blog.postman_collection -n 10
Will execute the collection 10 times.
If you have written tests to validate or pre-request scrips, these will also show in the summary.
This way you can now add the newman npm module to your package.json file and add as a step into your CI pipeline.
That’s all from me folks. I’ll soon write another blog series on how to write Selenium scripts. Stay tuned!