Using collection variable in test

Hi @timothy.jahn! Welcome to the Postman forum and community! :trophy:

The issue here is that you have used the pm.collectionVariables.get method, but you didn’t actually retrieve that value and assign it to a local variable. So in line 16, there’s no local variable actually called createdSegmentId. If you change line 14 to say the following, it should work:

let createdSegmentId = pm.collectionVariables.get("createdSegmentId");

Another option would be to avoid setting a local variable. To do that, you can retrieve the value of the collection variable directly in line 16 with the following:

pm.expect((jsonData.data.createLp.segmentId).to.equal(pm.collectionVariables.get("createdSegmentId")));

Hope that helps!

3 Likes