Set env variable from script and set next request

Your question may already have an answer on the community forum. Please search for related topics, and then read through the guidelines before creating a new topic.

Hi there, Having an issue with the test collection part of student expert. I am getting one failed test case: Set env variable from script and set next request | AssertionError: expected to have a length above 0 but got 0.
@suesmith please help with it. I have tied all possible things that have been discussed on the community forum regarding this issue…but not able to solve it.
MY COLLECTION LINK IS : https://www.getpostman.com/collections/3a681461e5f6328a8f6d

//set var from script and next request - make it env var so we check that too

pm.test("Set env variable from script and set next request", () => {

    //second folder should have set var and next req

    let testsArr = mockArr.filter(value => value.event).map(value => value.event); 

    console.log("testArr",testsArr);

    let execArr = testsArr.flat().filter(value => value.script.exec).map(value => value.script.exec); 

    var setsVars = execArr.flat().filter(p => p.indexOf('environment.set(')>-1); 

    console.log(setsVars);

    pm.expect(setsVars).to.have.length.of.above(0);

    var setsReqs = execArr.flat().filter(p => p.indexOf('.setNextRequest')>-1); 

    console.log(setsReqs);

    pm.expect(setsReqs).to.have.length.of.above(0);

}); 

This is the test script that checks that, try to print each lines output and try to understand what it is exactly looking for.

Hint: it is looking for script.exec in any of the requests and checks whether it has a postman.setNextRequest and pm.environment.

Hi, I have added the code in the second folder “Scripting and Collection Runs”. But there is a failing test case: Set env variable from script and set next request | ReferenceError: mockArr is not defined

If you have modified the test scripts , revert it back to what it was initially . Don’t modify the scripts in submit request

1 Like

Hi…Thanks for looking into my problem. I have reverted the test script, but the issue of the Test Collection folder still exists.

You have to click the share collection , and click update link for the changes to get reflected

1 Like