I'm not going to get into too many details about REST verbs or about Postman, because I have already done so in earlier blog posts. If you'd like to catch up on what I've written, you can start with this post and work your way forward week by week. You can also read this tutorial that I wrote for Simple Programmer.
This post will focus on how you can automate Services Tests. To demonstrate, I've created a collection of Postman tests that you can download from Github here. The API I'm testing is called Restful-Booker: it's a great easy API created by Mark Winteringham to help people learn how to test APIs.
Once you have downloaded the two files from Github, you can upload them in Postman to see what they do. To upload the collection, click on the Import button on the top left of the Postman window:
When the Import window pops up, click the Choose Files button and then navigate to the location of the file you downloaded called restfulbooker.collection.json. Click on that file name, and the collection will be imported:
Next, you'll need to upload the environment file. The environment file is what contains the variables that are used in the requests and assertions. To upload the environment file, click on the gear icon in the top right of the Postman window:
When the environment window pops up, click on the Import button, then on the Choose Files button, then navigate to the location of the downloaded file called restfulbooker.env.json. Click on that file name and the environment will be imported:
Finally, in the dropdown menu in the top right, select the Restful Booker environment:
You are now ready to run the requests from within Postman. Keep in mind that the tests are not idempotent: some of the requests depend on previous requests for setting variables and creating bookings, so while you are exploring you should run the requests in order.
Let's take a look at one of the requests and its assertions:
This is a GET request. The URL of the request is https://restful-booker.herokuapp.com/booking/1. The request is asking for the booking with the id of 1. You can see two tests in the Tests section: the first test verifies that the response code of the request is 200, and the second test verifies that "firstname" is one of the fields in the response.
Click the Send button to run the request, then scroll down to the bottom of the page:
Here you see the body of the response, which has returned a booking. You can also see a tab called Test Results, which shows that 2 out of 2 tests pass. If you click on this tab, you can see your results:
Now that you understand how the tests and assertions work, let's run them from the command line! In order to do this, you will need to have node.js installed. Installing node will also install npm, which is the node package manager. Then you can use npm to install Newman, the package that is used to run Postman tests. To install Newman, simply open your command-line window and type:
npm install -g newman
Once Newman is installed, navigate in the command-line window to the place where your restfulbooker.collection.json and restfulbooker.environment.json files are located. Now you can run your tests with this command::
newman run restfulbooker.collection.json -e restfulbooker.environment.json
(This command should be in a line with no returns; it's OK if it wraps around to a second line, though.)
The "-e" in this command stands for "environment". If all goes well, you should get a result that looks like this:
You can also run your tests from other file locations. To do this, simply specify the path to your files in your command. For example, if my files were in a folder called NightlyTests, which was in my Documents folder, and if I were using a Windows computer, I would use this command:
newman run C:\Users\KJackvony\Documents\NightlyTests\restfulbooker.collection.json -e C:\Users\KJackvony\Documents\NightlyTests\restfulbooker.environment.json
Now that you know how to run your tests from the command line, you can set up your tests to run automatically with a cron job or in a CI/CD platform such as Jenkins. Just be aware that whatever machine you run your tests on will need to have Newman installed.
You can also have your test results write to a file with the -r command. For example, you can have your results written in junit with this command:
newman run restfulbooker.collection.json -e restfulbooker.environment.json -r junit
When the tests are finished running, a Newman folder will be created with your test results inside.
I hope that this tutorial has given you some ideas about how you can automate your API testing! Next week we'll move on to UI tests with Selenium.
Nice post, thanks for this.
ReplyDeleteI'm glad you liked it, Arjun!
DeleteGreat post Kristin. Would love to see a follow up with your thoughts on what to test in services, such as contract validation etc. Also since REST APIs are stateless if you've encountered good ways to get around (hooks) initial authentication and basic calls to directly get to the endpoints being tested. Thanks!
ReplyDeleteI'm glad you enjoyed my post! I talked a bit more about what to test in API services in my blog posts from last February and March, so be sure to check those out! As for authentication, I've never found it to be a hassle in API testing, because it's so easy to save the token or cookie as a variable and use it in all subsequent requests. But another option would be to use mocks or stubs. Postman has mocking capabilities, but I haven't used them, so can't comment on how they work. However, I have written stubs directly into the code that will return a positive response for any call to the authenticated service, so that might be a route you could take. I hope this helps!
DeleteThe article is more informative. This is more helpful for our software testing training institute in chennai. Thanks for sharing
ReplyDeleteTop quality blog with excellent writing skills and information was very valuable thank you.
ReplyDeleteData Science Course in Hyderabad
Writing in style and getting good compliments on the article is hard enough, to be honest, but you did it so calmly and with such a great feeling and got the job done. This item is owned with style and I give it a nice compliment. Better!
ReplyDeleteCyber Security Training in Bangalore
I will really appreciate the writer's choice for choosing this excellent article appropriate to my matter. Here is deep description about the article matter which helped me more.
ReplyDeleteData Science Course
I am a new user of this site, so here I saw several articles and posts published on this site, I am more interested in some of them, hope you will provide more information on these topics in your next articles.
ReplyDeleteData Science Institute in Bangalore
Very good message. I stumbled across your blog and wanted to say that I really enjoyed reading your articles. Anyway, I will subscribe to your feed and hope you post again soon.
ReplyDeleteData Science Training in Pune
I think it would be easier to make video how you do it and publish on youtube. From this site https://viplikes.net I usually buy youtube likes for my video. You can do it too
ReplyDeleteExcellent Blog! I would like to thank for the efforts you have made in writing this post. Content shared was valuable and informative.
ReplyDeleteData Science Courses in Bangalore
have expressed a few of the articles on your website now, and I really like your style of blogging. I added it to my favorite’s blog site list and will be checking back soon…
ReplyDeleteDigital Marketing Training Institutes in Hyderabad
ReplyDeleteI see some amazingly important and kept up to a length of your strength searching for in your on the site
Digital Marketing Training Institutes in Hyderabad
Thanks for the Valuable information.Really useful information. Thank you so much for sharing. It will help everyone.
ReplyDeleteSASVBA is one of the leading training providers in the country. We provide AI training Course in Delhi accordance with current industry standards, allowing students to find their dream job in the world's leading companies. SASVBA specializes in teaching services, artificial lighting training that imparts practical knowledge through live project-based learning.
FOR MORE INFO:
Have you ever think to create tiktok profile? You could post there your test video. Read from here https://n4gm.com/tiktok-promotion-the-main-whys-and-hows-explained-to-you-by-professionals/ how to get followers for tiktok and think about it one more time
ReplyDeleteIt's like you understand the topic well, but forgot to include your readers. Maybe you should think about it from several angles.
ReplyDeleteBusiness Analytics Course
Informative blog post, thanks for sharing.
ReplyDeleteDigital Marketing Course with Internship
Thanks for your efforts in sharing this post with us. This was really awesome. kindly keep continuing the great work.
ReplyDeleteData Science Training in Hyderabad
Data Science Course in Hyderabad
Thank you for this post! I would make a video and publish it o youtube on your place. I have youtube channel where I always post my video. I buy youtube subscribers from here https://soclikes.com/ to grow my channel
ReplyDeleteThank you very much for this useful article. I like it.
ReplyDeletedata scientist course in malaysia
Thanks for such a great post and the review, I am totally impressed! Keep stuff like this coming.
ReplyDeletedata science course in malaysia
Thank you so much for doing the impressive job here, everyone will surely like your post.
ReplyDeletedata science course in malaysia
i am glad to discover this page : i have to thank you for the time i spent on this especially great reading !! i really liked each part and also bookmarked you for new information on your site.
ReplyDeletecyber security course in nashik
A great website with interesting and unique material what else would you need.
ReplyDeletedata scientist course
Very good points you wrote here..Great stuff...I think you've made some truly interesting points.Keep up the good work.
ReplyDeletedata science course
Thanks for posting this info. I just want to let you know that I just checked out your site and I find it very interesting and informative. I can't wait to read lots of your posts.
ReplyDeleteai course in hyderabad
Thank you for sharing this wonderful blog, I read that Post and got it fine and informative. Please share more like that...
ReplyDeleteEthical Hacking Institute in Bangalore
I wanted to thank you for this great read!! I definitely enjoying every little bit of it waiting for next one.
ReplyDeleteData Analytics Course in Chennai
This comment has been removed by the author.
ReplyDeleteReally impressed! Information shared was very helpful Your website is very valuable. Thanks for sharing.
ReplyDeleteData Science Course in Bangalore
Clayie is one of the Online Jhumka Delivery and Home Decor Items stores in India, also one of the leading Plants.
ReplyDeleteBuy Golden Jhumka
Buy Oxidized Earrings
Buy Oxidized Earring
Buy Oxidized Earrings
Buy Oxidized Earrings
Buy Oxidized Earrings
Wonderful content! Keep working on it! And if you have time, try checking out our website
ReplyDeleteWeb Design Company in Norwich
Web Development Company in Norwich
I found this blog very informative for automation services.
ReplyDeleteDo not miss out on the tremendous potential that AI and machine learning brings into the table. Contact us today to make the best of the AI based automation technologies services that we have.
Milestone Technologies provides global IT managed services that helps companies get the most of the digital and technology solutions such as Automated IT Service Desk, Digital Workplace Services, Modern IT asset lifecycle management, Modern AV VC Digital solutions, data center infrastructure services, Cognitive Automation solutions, Workforce Solutions
Private Toto is an online company that provides Internet sports betting. Various betting items will be provided to Toto users and the winner will be refunded according to the set dividend rate. And among Toto sites, private Toto sites with excellent capital are called safety playgrounds. 토토사이트 메이저놀이터 안전놀이터
ReplyDeleteMilestone Technologies provides global IT managed services that helps companies get the most of the digital and technology solutions such as Automated IT Service Desk, Digital Workplace Services, Modern IT asset lifecycle management, Modern AV VC Digital solutions, data center infrastructure services, best cognitive automation solutions, Workforce Solutions
ReplyDelete
ReplyDeleteThis is a great inspiring blog.You have shared really very helpful information thank you.
Data Scientist Course in Amritsar
Do not miss out on the tremendous potential that AI and machine learning brings into the table. Contact us today to make the best of Cognitive Automation solutions technologies that we have.
ReplyDeleteThis is an excellent article. I like this topic. I have found a lot of interesting things on this site. Thanks for posting this again.
ReplyDeleteBusiness Analytics Course in Jaipur
This post is very simple to read and appreciate without leaving any details out. Great work!
ReplyDeletedata science course in hyderabad
We provide well-informed, single points of contact for users to resolve issues and submit service requests. Contact us to know more about IT service desk automation
ReplyDeleteThanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts.
ReplyDeletecyber security training malaysia
토토365프로 Hi to all, the contents present at this site are actually amazing for people experience, well, keep up the nice work fellows.Feel free to visit my blog post..
ReplyDeleteThere are a very interesting question and very positive thinking 배트맨토토
ReplyDeleteI absolutely love your blog and find the majority of your post's to be what precisely I'm looking for. 스포츠토토티비
ReplyDeleteSuperb Information, I really appreciated with it, This is fine to read and valuable pro potential, I really bookmark it, pro broaden read.
ReplyDeleteAppreciation pro sharing. I like it.
K-Nearest Neighbour (KNN) algorithm is one of the uncomplicated ML algorithms based on the Supervised Learning Technique. It assumes the similarities between the new and available data and categorizes them based on pre-existing groups while storing all the available data. KNN incorporates a data point based on similarities of new and old data. It is used for both regression and classification of data, but the latter is used frequently. To learn more about KNN start your Data Science training today with 360DigiTMG.
ReplyDeleteData Science in Bangalore
It would help if you thought that the data scientists are the highest-paid employees in a company.
ReplyDeletedata science course in kochi
I’m looking forward to reading more informative articles like this. It contains a wide spectrum of details and information for students who want to enrol in a proper course curriculum and are looking for good options. Best Data Science Institute In Chennai With Placement
ReplyDeleteThank you for sharing the valuable article with us. if you want to know more about Plant automation In Cement Industry click here and read the article
ReplyDeleteThanks! Very interesting to read. This is really very helpful. Best Data Science Course In Kerala By Digiperform
ReplyDeleteDiscover viAct cutting-edge EHS Monitoring Solution
ReplyDeleteand revolutionize your workplace safety. Monitor, analyze and improve with ease. Request a Demo.
The success of a test automation company largely depends on the tools and technologies it employs. At Kualitatem, we utilize a wide array of advanced automation tools and frameworks to deliver exceptional test automation services.
ReplyDeleteThanks for sharing the article to us.
ReplyDeleteGenerative AI for Contract summarization and verification