![]() ![]() But basically, view the "Tests" functionality as "Code to run after request is completed" functionality. ![]() There are many ways to hack this in Postman: in the request, at a folder level, at a collection level, or possibly re-using a script created by a collection. var response = JSON.parse(pm.response.text()) Ĭonsole.log("length : " + ) #POSTMAN CONSOLE OUTPUT CODE#The code below parses the response and logs to the Postman Dev console the number of items returned in the "to-do's" array in the response. I can write any arbitrary code I want in the Postman "Tests" or "Pre-request Script," and I can use that to support my testing, not just assert on values.Į.g. Starts at 0 so when it shows 201 at the bottom, it means there are 202 to-do's in the returned array. Then, use the pretty print view to see how many items are in the JSON array. In Postman show the console with "View \ Show Postman Console" Using the Pretty Print View in Postman Console Using the JSON filter in Insomnia Response view todos.length It has a handy filter facility in the Response, which I can use to show the number of to-do's returned. Insomnia is a REST Client that I often use for Exploratory testing. Using the JSON Filter in Insomnia Response View todos.length I'll write up a fuller set of learnings on Postman scripting in a later post. I hadn't used the Postman scripting before, so I learned a new set of knowledge when I tried that out. Send Requests/Response through a Proxy and use the Proxy viewer.Paste the JSON into a browser dev console. ![]() Script in Tests in a request in Postman.Using the pretty print view in Postman console.Using the JSON filter in Insomnia Response view.How many ways are there to count the values in a JSON array returned from a REST API call? I used this limitation as a Personal Test Improvement Exercise. feature requests for testing can be usefulīut my only option made me realize that I didn't have enough workarounds available in my mind to handle this situation.I wrote some comments to Elisabeth and Thomas, and at the time, the only "workaround" I could think of was to use Insomnia because that can show a filter count in the responses. GET /todos returns a list of to-do's, but if there are a lot of them then it can be hard to know how many are there.Įlisabeth and Thomas were using Postman to test the app, and Postman does not show how many items are returned. One note in the write-up mentioned that it could be useful if the responses described how many items were returned.Į.g. I've been working on Thingifier, which at the moment exposes a REST API for a simple To-Do ManagerĮlisabeth Hocke and Thomas Rinke bravely picked the app to perform some testing on and created a useful write-up. If you identify other ways to count the JSON than I did, then I'd be interested in learning, so send me a message or leave a comment somewhere. I learned some new stuff along the way and remembered some old stuff. ![]() I eventually came up with six different ways to count the number in the array before I stopped. I used Thingifier, created a bunch of "to-do's" and then used GET /todos to return an array of "to-do's"
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |