Hi! I created my collection in postman and it works correctly, but I would like to execute it using newman. In my collection the tests are in a specific package, in each call the tests are called directly from the package: const getDs = pm.require(‘get_ds’);
At this point:
I proceed by exporting the collection in json format
I open the command line and execute: newman run collection.json
But the execution fails: TypeError in test-script.
If I check the json file of the collection, I see that in the specific calls the packages are called, but they are not part of the json.
If instead of using the packages, in the individual calls I write the test in each one and then export the json, newman works.
How can I make newman read, in addition to the json of the collection, also the package?
Hi @danny-dainton thank you for your reply, but it doesn’t solve the problem: I used postman cli to execute my collection, but the result is always the same; if I run the collection directly from postman, it is ok:
Loading packages...[0/1] [Error]
1⠄ Error in test-script
Hi @danny-dainton yes, of course:
this is my script in the package:
function Status_200() {
pm.test("Status test", function () {
if (pm.response.code === 200) {
console.log("Status is OK");
} else {
throw new Error(`Expected status 200 but got ${pm.response.code}`);
}
});
}
// Call the test function
Status_200();
// Export the function to be used in other modules
module.exports = {
Status_200
};
and I call it in each get as follow in the script section of each get:
This would work with the Postman CLI, if you were logged in, then the package id in the exported JSON file, would be read and used correctly in the run.