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.
At every pre-request section of sub folder having pre-requist script to execute required folders.my script to run/skip folders
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’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.