0
votes

We have a lot of API level automated tests written as collections of requests in Postman.

We have a script to run all collections in automated manner.

Is there a way to label/run only subset of requests e.g. with some label e.g. as smoke suite, without copying requests to new collection(s) and run then explicitly (as this yields the need to maintain same tests in 2 places...)?

There might be labels, groups or some script that skips the request is env variable is set...

2
There's got to be a better way to do this than create folders that are largely redundant. Maybe version control? But it really feels like there should be a feature where one could disable a query based upon some environment variable, filter queries to run in Runner or something like that.Rob
just press ctrol+o to import and choose link , and use that linkPDHide

2 Answers

1
votes

you can create folders and organize test like

  1. smoke_and_regression
  2. smoke_only etc

you can specify which folder to run using --folder arguent when using newman as command line tool

you can also control the execution flow using postman.setNextRequest .

and also you can run newman as an npm module.

you just need to write a logic to read the collection file and get all folder names containing "smoke" for eg and pass it as an array

const newman = require('newman'); // require newman in your project

 

// call newman.run to pass `options` object and wait for callback
newman.run({
    collection: require('./sample-collection.json'),
    reporters: 'cli',
    folder: folders
}, function (err) {
    if (err) { throw err; }
    console.log('collection run complete!');
});

Just update for the comments:

in old and new UI you can select which folder to execute in collection runner

enter image description here

1
votes

Get all requests in the collection:

you can also get information about all the requests in a collection by using :

https://api.getpostman.com/collections/{{collection_UUID}}

to get uuid and api key goto :

https://app.getpostman.com

Now for generating api key >

goto account settings > api key and generate api key.

to get collection uuid goto specific workspace and collection and copy the uuid part from url:

enter image description here

Now in your collection

Rename all requests as:

get user details [Regression][Smoke][Somethingelse]
get account details [Regression]

Then Create a new request called initial request and keep it as the first request in your collection:

url: https://api.getpostman.com/collections/8xxxxtheuuidyoucopied

authorization: apikey-header : key: X-Api-Key and value: yourapikey

test-script :

pm.environment.unset("requestToRun")
reqeustlist = pm.response.json().collection.item.map((a) => a.name)
requestToRun = reqeustlist.filter((a) => a.includes(pm.environment.get("tag")))
let val = requestToRun.pop()
pm.environment.set("requestToRun", requestToRun)
val ? postman.setNextRequest(val) : postman.setNextRequest(null)

Now set the envirnoment variable as what you want to look for eg: run script that contains text "Regression" then set pm.environment.set("tag","Regression")

Now in your collection-pre-request add:

if (pm.info.requestName !== "initial request") {
    let requestToRun = pm.environment.get("requestToRun")
    let val = requestToRun.pop()
    pm.environment.set("requestToRun", requestToRun)
    val ? postman.setNextRequest(val) : postman.setNextRequest(null)
}

Output:

enter image description here

Example collection:

https://www.getpostman.com/collections/73e771fe61f7781f8598

Ran only reqeusts that has "Copy" in its name