![]() ![]() (Replace " getPostmanAuth" with your JSON file name.) Here, the magic begins! Run the Newman command: newman run getPostmanAuth.json When you're done, open the command line and navigate to the path of the just exported JSON collection file.įor me, the command will look like this: cd ~/Projects/Postman I will do it in ~/Projects/Postman/getPostmanAuth.json. Now, save the file in any preferred location and name it what you like. To do that, highlight your collection and then click on "Export." no, I will not comment on that.Īs a first step, we need to export our Collection to a JSON file in Postman format. But wait, that's manual, isn't it? Yes, we need to test automatically, because in the 21st-century manual testing is. Ok, let's say we finished collecting our tests together, what's next? We can easily rerun them as many times as we need. The power behind this is JS, making is quite easy to write many tests for specific coverage, including schema validation for a JSON response body, and much more. Now we can make sure that our API GET request is responding with the 401 HTTP code. ![]() With a slight change, it looks like this: tests = de = 401 When using JavaScript in Postman (you can also use other languages), there are some predefined JavaScript code widgets that should be used. Tests = postman.getResponseHeader("WWW-Authenticate") Ī couple of words about the tests. Tests = postman.getResponseHeader("Server").has("nginx/1.10.1") Tests = postman.getResponseHeader("Server") Tests = postman.getResponseHeader("Connection").has("keep-alive") Tests = postman.getResponseHeader("Connection") Tests = postman.getResponseHeader("Date") Tests = responseBody.has("Unauthorized") Here are the tests: postman.cleanGlobalVariable("variable_key") In this collection, we should include all the API tests we created for this sample API. Now let's see what we can achieve here.įirst of all, we need to create our first collection in Postman. To do that, I will test a sample API from Postman, which is a simple GET request. In this blog post, I will show you how to use Newman. By using Newman, we can integrate API test automation to Continuous Integration tools. Newman is a command line executor for Postman tests, enabling you to run a Postman collection from the command line. Newman is a nice part of Postman, and it makes Postman more powerful. If you want to learn how to use Postman, check out this blog post "How to Use Postman to Manage and Execute Your APIs." It also provides lots of useful functionalities on top of the main HTTP requests like API documentation, monitoring, simulating a mock server, etc. Postman is a tool for sending requests to API endpoints. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |