Skip to main content

Posts

Showing posts with the label Postman

Postman CLI Vs Newman

The Postman v10 release in Q3 of 2022 introduced the Postman CLI. If you are interested to know whether you should move from Newman to Postman CLI, please go through this: https://learning.postman.com/docs/postman-cli/postman-cli-overview Here is a direct comparison table: Postman CLI Vs Newman: https://learning.postman.com/docs/postman-cli/postman-cli-overview/#comparing-the-postman-cli-and-newman This should help to decide which command-line companion to use: https://learning.postman.com/docs/postman-cli/postman-cli-overview/#deciding-which-command-line-companion-to-use My 2 cents: Of course, Newman is not deprecated ( yet ) but I think it can be the case that the Postman team will work more actively on Postman CLI than Newman. If you are an existing Newman user, there is no push right now to move to Postman CLI. However, if you are just getting started with grokking backend automation with Postman then give it a shot to Postman CLI.

Pynt - free API security solution

  Pynt is a free API security solution that generates automated security tests based on your existing functional test collection within postman. It appeals to perform dynamic security testing covering all the OWASP API Top 10. More details:  https://www.postman.com/pynt-io/workspace/pynt/overview I tried and it looks promising. #pynt   #postman   #apisecurity   #testing   #security

Want to auto retry a failing request in postman based on a set number of max tries and with a certain amount of wait time?

  Of course, there are many ways to tackle it but I have mentioned below one of the ways where you can use the given code in the Tests tab of the postman. Unfortunately, in some of the lower environments, there can be a situation where you request fail at times due to infra issues, timeouts, etc., so in that case, this can be super helpful: var notExpectedText = 'Failed'; var maxTries = 3; var pauseBetweenTries = 5000; if (!pm.environment.get("tries")) {     pm.environment.set("tries", 1); } if ((pm.expect(pm.response.text()).to.not.include(notExpectedText)) && (pm.environment.get("tries") < maxTries)) {      var tries = parseInt(pm.environment.get("tries"), 10);      pm.environment.set("tries", tries + 1);      setTimeout(function() {}, pauseBetweenTries);      postman.setNextRequest('PaymentService'); //here you should give your request name that you want to retry on failure  } else {   ...

How to run your postman (Newman) automation collection in a Continuous Integration environment like Azure DevOps build Pipeline?

  How to run your postman (Newman) automation collection in a Continuous Integration environment like Azure DevOps build Pipeline? Postman Introduction: Postman is a tool that simplifies each step of building and testing APIs. If you've ever used it in your development or testing phase, you must already know what an incredible tool it is. It presents the possibility to automate your API tests and integrate them into your CI/CD pipeline to make certain that any code changes won’t introduce any new regression issues in upper environments like QA, Stage, Production, etc. Newman Introduction: Newman is a tool, using which one can effortlessly run and test Postman Collections directly from the command line. Azure DevOps CI/CD Introduction: Azure DevOps by Microsoft Azure is one of the leading tools that automate CI/CD's process. Using continuous integration and continuous deployment with Azure DevOps, these pipelines are used to construct build-deploy-test workflows used mainl...

Postman: Parse XML and response data value verification using the cheerio library

How to parse XML and validate the response fields using the cheerio library in postman? Sample URL :  https://www.w3schools.com/xml/tempconvert.asmx Sample Request Payload : <soap12:Envelope xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance " xmlns:xsd=" http://www.w3.org/2001/XMLSchema " xmlns:soap12=" http://www.w3.org/2003/05/soap-envelope ">     <soap12:Body>         <FahrenheitToCelsius xmlns=" https://www.w3schools.com/xml/ ">             <Fahrenheit>108</Fahrenheit>         </FahrenheitToCelsius>     </soap12:Body> </soap12:Envelope> Expected Response : <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap=" http://www.w3.org/2003/05/soap-envelope " xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance " xmlns:xsd=" http://www.w3.org/2001/XMLSchema ">     <soap:Body>         ...

NPM: peer dependency is not detected for global packages

  Issue : In npm, peer dependency is not detected for global packages like when you try to install "newman" and then install "newman-reporter-htmlextra" so that you can run Postman/Newman tests collection with htmlextra reporter, it keeps failing because no suitable Newman version is found: npm install -g newman npm install -g newman-reporter-htmlextra newman run "Publish.postman_collection.json" -e QAUS.postman_environment.json -r htmlextra --reporters cli,junit,htmlextra  --reporter-htmlextra-export TestReport.html You may get this error: "npm WARN newman-reporter-htmlextra@1.20.4 requires a peer of newman@^5.1.2 but none is installed. You must install peer dependencies yourself" Solution : Peer dependency and the required package should be installed together like:  npm install -g newman newman-reporter-htmlextra

Encode/Decode the variable/response using Postman itself

We get a lot of use cases where we may have to implement Base64 encoding and/or decoding while building our APIs. And, if you are wondering if it is possible to encode/decode the variable/response using Postman itself or how to encode/decode the token or password in postman and save it in a variable? To Base64 encode/decode, the quickest way is to use JavaScript methods btoa, atob: atob - It turns base64-encoded ASCII data back to binary. btoa - It turns binary data to base64-encoded ASCII. Sample code : var responseBody = pm.response.json(); var parsedPwd = JSON.parse(atob(responseBody.password)); // presuming password is in the payload pm.collectionVariables.set("password", parsedPwd);

Monitor your APIs in postman

If you are not using any CI/CD tool like Jenkins, Azure DevOps, etc. but still want to schedule your postman automation collection suite to check the health and performance of your APIs; then you can use Monitor option provided by Postman.   You can also enable email notifications for failures and can configure the available integrations to receive alerts in tools like Slack, PagerDuty, etc. Check here for more details: https://learning.postman.com/docs/designing-and-developing-your-api/monitoring-your-api/setting-up-monitor and https://www.postman.com/pricing/   Note* With the FREE plan, we get only 1000 hits/requests per month as of writing this post.   You can monitor the performance on your account web dashboard as shown below.

Steps to execute postman collection through newman

  Here is what you need to do to start executing the postman collection through newman on your system: 1. Install NodeJS – https://nodejs.org/en/download . Click on the 32-bit or 64-bit Windows Installer package, depending on your machine configuration. Skip this if NodeJS/npm is already installed on your system. 2. Open a command prompt, and type “node -v” and "npm -v". These commands should work and provide version number if nodeJS installation is successful. 3. Run this command to install newman:   npm install -g newman 4. Install npm package newman-reporter-htmlextra for creating reports.   npm install -g newman-reporter-htmlextra 5. Pull/Export the collection, environment json (if any), test data csv (if any) files from the Postman UI or code repo (git) to your local and run this command through the folder on your local where you have these files: Command where you have collection json and environment json file : newman run "<<your_collectio...

Tips and tricks for automation using Postman/Newman

   1. How do we run multiple newman/postman collections sequentially (back to back) at one run ? Batch running multiple newman/postman test collections : Create a batch file like this and run: call newman run Collection1.postman_collection.json -e qa1.postman_environment.json -r htmlextra --reporters cli,junit,htmlextra --reporter-htmlextra-export TestReport1.html -d TestData1.csv call newman run Collection2.postman_collection1.json -e qa2.postman_environment1.json -r htmlextra --reporters cli,junit,htmlextra --reporter-htmlextra-export TestReport2.html -d TestData2.csv   Side note : Give a shot to https://medium.com/@mnu/run-multiple-postman-collection-in-parallel-stress-ee20801922ed in case you would like to run it in parallel (P.S. haven’t tried this yet)   2. How can we set environment variable based on another environment variable value ? Like for QA1, we need accountNo say "123" but for QA2, we need accountNo say "345", etc.   pm.tes...

Best practices for API automation using Postman

1. Always use Collections and organize tests into folders for testing : Even Though the collection is the top-level of organization, we should have folders that can group together related to requests or demonstrate a detailed workflow. As our API grows in number and complexity, it will become important to organize our tests so they make sense and can be found easily. Therefore, we suggest using folders/sub-folders to group requests by resource, module type, test suite, and workflows. P.S. If require, we can run specific folder(s) inside a collection using “ –folde r ” argument. 2) Use global/environment/collection variables :  Postman also allows us to store data from previous tests into global/collection variables. These variables can be used exactly like environment variables. For example, there is an API that requires data received from another API ( chaining/correlation ). We can store the response attribute (or part of the response) and use that as part of a request ...

Azure DevOps Postman/Newman HTML Report

 In Azure DevOps, if you don't want JUnit Test results and like to have a HTML Report (htmlextra) that newman provides which is very neat and comprehensive, go for this FREE extension: https://marketplace.visualstudio.com/items?itemName=MaciejMaciejewski.postman-report   This lets you create a task for publishing newman HTML Reports in your pipeline into Azure Storage(like shown below in Image 1). And then, embedded reports can be viewed as a tab in Build and Release result page (like shown below in Image 2). Plus, there is an option to download the reports from the same tab.