Hi
I adapated this help to write postman responses to files (https://github.com/postmanlabs/postman-app-support/issues/3033#issuecomment-301758179). Here are files used
SIA_Ext_Gateway Additional Test Cases.postman_collection.json ,
writeToDiskSIA_EXt_GatewayAdditionalTestCasesKN.js
However when i run the files i get the following error
SyntaxError: Unexpected token S in JSON at position 0
at JSON.parse (
at EventEmitter.
at EventEmitter.emit (C:\npmnode_modules\newmannode_moduleseventemitter3index.js:203:33)
at Function.callbacks.(anonymous function) [as request] (C:\npmnode_modules\newman\lib\runindex.js:191:34)
at afterRequest (C:\npmnode_modules\newmannode_modulespostman-runtime\lib\runnerextensions\http-request.command.js:85:35)
at complete (C:\npmnode_modules\newmannode_modulespostman-runtime\lib\runnerextensions\http-request.command.js:137:33)
at C:\npmnode_modules\newmannode_modulespostman-runtime\lib\runnerextensions\http-request.command.js:182:29
at C:\npmnode_modules\newmannode_modulesasync\distasync.js:1140:9
at C:\npmnode_modules\newmannode_modulesasync\distasync.js:473:16
at replenish (C:\npmnode_modules\newmannode_modulesasync\distasync.js:1006:25)
at C:\npmnode_modules\newmannode_modulesasync\distasync.js:1016:9
at _asyncMap (C:\npmnode_modules\newmannode_modulesasync\distasync.js:1133:5)
at C:\npmnode_modules\newmannode_modulesasync\distasync.js:1219:16
at C:\npmnode_modules\newmannode_modulesasync\distasync.js:1046:16
at Object.
at Object.
One thing i can understand is that there is a problem in parsing the JSON response ? so can we say that it is not giving a proper JSON response ? or where the issue is
NewMan_response.txt
SIA_Ext_Gateway Additional Test Cases.postman_collection.json.txt
writeToDiskSIA_EXt_GatewayAdditionalTestCasesKN.js.txt
Thanks a lot
@kthulsidoss The error message indicates that one of the responses returned by your API was non JSON. In the file writeToDiskSIA_EXt_GatewayAdditionaTestCasesKN.js, there is a statement that pushes responses into an array:
results.push(JSON.parse(body));
This will fail if any of the response bodies is not JSON. There are two ways to rectify this: (you'll have to update the code in writeToDiskSIA_EXt_GatewayAdditionaTestCasesKN.js to fix the issue)
JSON.parse function call can be removed altogether, so that responses are pushed into the array directly, like so:results.push(body);
try {
results.push(JSON.parse(body));
}
catch (err) {
// the JSON.parse call failed, handle the error appropriately
}
Most helpful comment
@kthulsidoss The error message indicates that one of the responses returned by your API was non JSON. In the file
writeToDiskSIA_EXt_GatewayAdditionaTestCasesKN.js, there is a statement that pushes responses into an array:This will fail if any of the response bodies is not JSON. There are two ways to rectify this: (you'll have to update the code in
writeToDiskSIA_EXt_GatewayAdditionaTestCasesKN.jsto fix the issue)JSON.parsefunction call can be removed altogether, so that responses are pushed into the array directly, like so: