Hello @gbadebo-bello . I have a simple example collection where I can get the error. The collection has two folders. Each folder has the same post-request script. Each script declares a “responseBody” variable. I can get the error by running the command npx newman run Temp.postman_collection.json --folder folder_one
or npx newman run Temp.postman_collection.json
.
It looks like I can’t upload a json file, I will just paste the contents here.
{
"info": {
"_postman_id": "fake_id",
"name": "Temp",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "36314241",
"_collection_link": "https://fakeurl"
},
"item": [
{
"name": "folder_one",
"item": [
{
"name": "Postman Echo One",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
"if(pm.collectionVariables.has('env')) {\r",
" console.log('collectionVariables includes environment variables')\r",
"}\r",
"\r",
"if(pm.variables.has('env')) {\r",
" console.log('pm.variables includes environment variables')\r",
"}\r",
"console.log('Pre-request script ran at request level.')"
],
"type": "text/javascript",
"packages": {}
}
},
{
"listen": "test",
"script": {
"exec": [
"const responseBody = pm.response.json();\r",
"\r",
"console.log(responseBody.args);\r",
"\r",
"pm.test(\"Status code is 200\", function () {\r",
" pm.response.to.have.status(200);\r",
"});"
],
"type": "text/javascript",
"packages": {}
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://postman-echo.com/get",
"protocol": "https",
"host": [
"postman-echo",
"com"
],
"path": [
"get"
]
}
},
"response": []
}
]
},
{
"name": "folder_two",
"item": [
{
"name": "Postman Echo Two",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
""
],
"type": "text/javascript",
"packages": {}
}
},
{
"listen": "test",
"script": {
"exec": [
"const responseBody = pm.response.json();\r",
"\r",
"console.log(responseBody.args);\r",
"\r",
"pm.test(\"Status code is 200\", function () {\r",
" pm.response.to.have.status(200);\r",
"});"
],
"type": "text/javascript",
"packages": {}
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://postman-echo.com/get",
"protocol": "https",
"host": [
"postman-echo",
"com"
],
"path": [
"get"
]
}
},
"response": []
}
]
}
],
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"packages": {},
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"packages": {},
"exec": [
""
]
}
}
],
"variable": [
{
"key": "collectionVariable",
"value": "1",
"type": "string"
},
{
"key": "tmp",
"value": "tmp",
"type": "string"
},
{
"key": "env",
"value": "collection_env",
"type": "string"
}
]
}