Newman Run Issue for subfolders collection

I have set of folders inside a collection.I need to pick and skip folder with passing folder names from environment file which has been formatted as array.

image

At every pre-request section of sub folder having pre-requist script to execute required folders.my script to run/skip folders

Env File config set picture:
image

const testCaseIDs = JSON.parse(pm.variables.get(‘testCaseIDs’));

let  isTest = false;

_.forEach(testCaseIDs, (testCaseID) => 
{
    const requestNames = pm.execution.location;

let i=0;

 for (i; i < requestNames.length; i += 1) {
    
   var requestName=requestNames[i];
    if(testCaseID===requestName) 
    {
        isTest = true;
    }
 }
    
})

if (!isTest) {
    console.log( "Test is Skipped");
    pm.execution.skipRequest();
} else {
    console.log("Test is Executed");
}

My problem is executing folders as per env file input when at newman
But when trying to run via newman,not running as per expected.I don’t know what is going on newman.It is showing all tests as passed as well as failed

Actual,I passed the input to pick only folder 2,3 but not skipped folder 1 and run the all the folder two times and marked all as passed aswell failed

I am not faced any issues in postman and required input based folder is skipped/executed

I’m not really following your logic in the code you posted.

Please use the preformatted text option in the editor when pasting code (to prevent everything being aligned to the left and hard to read).

Taking it back a step.

Your testCaseID’s don’t appear to be test case ID’s but folder names.

On face value, it looks like you need to compare the list of folders from the environment variable with the current folder for the request that is about to run.

Therefore, you just need to get the array of folders from the environment variable and then use pm.execution.location to get the current folder name.

pm.execution.location returns the full path of → Collection,folder,request

So to return the current folder name, you could use.

console.log(pm.execution.location[pm.execution.location.length -2]);

A working example…

let allowedFolderNames = ["folder1","folder2","folder3"]
let currentFolder = pm.execution.location[pm.execution.location.length -2];
const folderCheck = allowedFolderNames.includes(currentFolder);
console.log(folderCheck);
1 Like

Thanks for you help @michaelderekjones…It is working for me…

pm.execution.location script not working in newman

pm.execution.location is a fairly new feature.

I wonder if it hasn’t made it into Newman yet?

Are you using the latest version as an initial check?

Otherwise, someone from Postman would have to advise on when this might be coming to Newman.

1 Like

@michaelderekjones Hi,Tried after updating my newman version to latest.
Now it is working fine.

Thanks a lot for your help/reply…

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.