Skip to main content

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.test("Set environment variable_value based on Env type.", function () {

    if (pm.environment.get('env') == 'qa1') {

        pm.environment.set("variable_key", "variable_value");

    } else if (pm.environment.get('env') == 'qa2') {

        pm.environment.set("variable_key", "variable_value");

    } else if (pm.environment.get('env') == 'qa3') {

        pm.environment.set("variable_key", "variable_value");

    }

});

 

3. How to set request workflows?

When you start a collection run, all requests are run in the order you see them in Postman. So, all requests are executed first, by order of the folder, and then any requests in the root of the collection.

However, you can override this behavior using a built-in function called postman.setNextRequest(“request_name”). This function, as the name suggests, allows you to specify which request runs next.

NOTE: Name of the request should be exactly same as you have written while naming the request as it is case sensitive.

More details: https://learning.postman.com/docs/running-collections/building-workflows/

 

4. How to skip test based on environment?

There are many ways to achieve it but the easiest one would be setting the env variable and use that in your script, like:

const skipTest= pm.environment.get('env') == 'Prod';

(skipTest ? pm.test.skip : pm.test)("Check Prod requests", function()

{

const response = pm.response.json();

pm.expect(response.key).to.eql(“XXXX-XXX”);

});

 

5. How to set delay while running a collection?

newman run collection.json --delay 10000

 

6. How can we run specific folder(s) inside a collection?

Use the argument: --folder <name>
Run requests within a particular folder or/and folders or specific requests in a collection. Multiple folders or requests can be specified by using --folder multiple times, like: --folder f1 --folder f2

Sample:

newman run "<<yourCollection.postman_collection.json>>" -e <<yourEnvironment.postman_environment.json>> --folder "<<folderName1>> --folder "<<folderName2>>" -r htmlextra --reporters cli,junit,htmlextra --reporter-htmlextra-export TestReport.html

 

7. Looking for an extensive report after your execution run?

Please check here: https://github.com/DannyDainton/newman-reporter-htmlextra

It comes with a nice dashboard style. It is very precise and concise one- I love it.


Comments

  1. Nice. Do you have an example of #1 in javascript, not shell?

    ReplyDelete
    Replies
    1. Give a shot to this https://community.postman.com/t/required-to-run-multiple-collection-through-newman/10792/6

      Delete

Post a Comment

Popular posts from this blog

Clipboardy: Node.js library

 Clipboardy is a popular Node.js library that provides a cross-platform solution for interacting with the system clipboard. It supports both synchronous and asynchronous operations, and it can be used to copy, paste, and read the clipboard contents. Features of Clipboardy: 1. Cross-platform compatibility: It works on macOS, Windows, Linux, OpenBSD, FreeBSD, Android with Termux, and modern browsers. 2. Synchronous and asynchronous operations: It provides both synchronous and asynchronous methods for clipboard operations, making it suitable for a variety of use cases. 3. Copy, paste, and read operations: It supports copying, pasting, and reading the clipboard contents, making it a versatile tool for interacting with the clipboard. 4. Promise-based API: It is an asynchronous method that returns promises, making it easy to handle asynchronous operations in a clean and concise way. 5. Easy to use: It has a simple and intuitive API that is easy to learn and use. How to Use Clipboardy: To...

ARIA Snapshot in Playwright

  What is an ARIA Snapshot in Playwright? An  ARIA snapshot  in Playwright is a structured representation of a page’s  accessibility tree , which is used by assistive technologies (e.g., screen readers) to interpret the content of a web page. This snapshot helps verify if elements have the correct  roles, names, and properties  required for accessibility. Playwright provides the page.accessibility.snapshot() API to capture this accessibility tree at any given moment during test execution. How Does ARIA Work? ARIA ( Accessible Rich Internet Applications ) is a set of attributes that help improve accessibility by defining roles, states, and properties for elements that are not natively accessible. Example: In this case, the aria-label ensures that screen readers identify the button as “Submit Form.” How to Use ARIA Snapshots in Playwright? Playwright’s  accessibility.snapshot()   method retrieves the  accessible structure  of the page. Ex...

Bruno vs Postman: Which API Client Should You Choose?

  As API testing becomes more central to modern software development, the tools we use to test, automate, and debug APIs can make a big difference. For years, Postman has been the go-to API client for developers and testers alike. But now, Bruno , a relatively new open-source API client, is making waves in the community. Let’s break down how Bruno compares to Postman and why you might consider switching or using both depending on your use case. ✨ What is Bruno? Bruno is an open-source, Git-friendly API client built for developers and testers who prefer simplicity, speed, and local-first development. It stores your API collections as plain text in your repo, making it easy to version, review, and collaborate on API definitions. 🌟 What is Postman? Postman is a full-fledged API platform that offers everything from API testing, documentation, and automation to mock servers and monitoring. It comes with a polished UI, robust integration, and support for collaborati...