rustnnespp
(Diego Bandeira)
November 22, 2024, 9:52pm
1
Suppose that a collection has a folder A containing sub-folders B and C.
Folder A contains some code in the pre-request script that uses a package. Sub-folders B and C require this code to run correctly.
I have managed to run the sub-folder C via newman, but it seems the code in Folder A isn’t executed.
That collection runs as expected using Postman.
Is that a way to ensure that the code in Folder A runs before sub-folder C using newman?
Thanks in advance.
Hey @rustnnespp
Can you share a visual example of this flow and the command that you’re using to run that folder with Newman, please?
It’s much easier for people to see exactly what you’re doing rather than a hypothetical A,B,C scenario which doesn’t include any real context.
rustnnespp
(Diego Bandeira)
November 26, 2024, 2:10am
3
Hey @danny-dainton , thanks for the reply.
I’m using the example code in Newman’s GitHub page , with some edits:
require("dotenv").config();
const newman = require("newman");
const USER_ID = process.env.USER_ID,
COLLECTION_ID = process.env.COLLECTION_ID,
ACCESS_KEY = process.env.ACCESS_KEY;
var options = {
collection: `https://api.postman.com/collections/${USER_ID}-${COLLECTION_ID}?access_key=${ACCESS_KEY}`,
iterationCount: 1,
reporters: ["cli", "junit"],
folder: [/* folder id collected in Postman, without the user id */] ,
delayRequest: 1000,
reporter: {
junit: {
export: "./reports/junit.xml",
},
},
};
newman
.run(options)
.on("start", function (err, args) {
// on start of run, log to console
console.log("running a collection...");
})
.on("done", function (err, summary) {
if (err || summary.error) {
console.error("collection run encountered an error.");
} else {
console.log("collection run completed.");
}
});
Running this code gets me to the errors below:
It’s unclear to me, but it seems that those errors refer to the code in the collection that calls functions in the package I’ve created, which works in Postman.
Let me know if you need more info.
Thanks for sharing that.
What scripts do you have in the pre/post script sections? Are you using the Package Library?
rustnnespp
(Diego Bandeira)
November 26, 2024, 11:57am
5
Yes, I’m using a Package library. This package has several functions, like authentication and string generation, for example.
The pre-request script in the collection, which causes the errors reported above, calls some of those functions in the package library.
That’s where your issue is coming from - The Package Library is not part of Newman so any Collection that’s calling those scripts from the Library is going to error.
That would all be working within the platform as Newman isn’t involved and the Desktop/Web platform has access to those scripts.
The Postman CLI will allow you to run a Collection with a Package Library script but this is limited by plan type.
system
(system)
Closed
November 29, 2024, 12:43pm
8
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.