These two files are in the same folder as the script I’m running.
collection: require(’.\Orders_1.postman_collection.json’),
enviornment: require(’.\Innovations odc Lab01.postman_environment.json’),
I get the report and the “collection run complete!” message and no other errors in the cli.
BUT my tests in the collection are failing because it can’t find the addrinfo. Error: getaddrinfo ENOTFOUND {{url}}{{basepath}}
The url and basepath variables are in the enviornment json file along with valid keys.
Yeah, that was it. I guess syntax highlighting isn’t available for newman scripting in VS Code.
Thank you!
BTW Do you use the newman library by any chance?
We’re in the initial stages of creating our API (as well as the tests) and I’m looking for the easiest way to run collections via script and maintain them.
I’m leaning towards using the library as working with newman cli and batch scripts seems sub-optimal.
Although, I’m using file exports to run my newman scripts, which is too much work.
I would have expected that to be flagged at the very least, as a typo (depends what you’re VSCode setup is like) but there should also be the auto completion coming from the Newman library with would tell you what properties can be added to that run object.
To use the most upto versions of your Collections I would opt for using the Postman API. Using the direct link to the collection would aviod having to download/export the static files each time you make a change.
Error: collection could not be loaded
** Error fetching the collection from the provided URL. Ensure that the URL is valid.**
** Invalid API Key. Every request requires a valid API Key to be sent.**
The postman_api_key is in the enviornment.json.
Also, is there some documentation that covers this?
The only newman docs I found are on their Github page and it’s not all that great.
That’s not going to know what that api key is, if you use it like that.
You’re basically asking your node script to look into the environment file to find an API Key in a format only known, to a Collection.
Outside of a Collection, that {{..}} syntax is unknown. You’re working with a node JS script there so you would need to reference that key value with a variable known to that script or hardcode it.
That’s just a URL that happens to return your Postman Collection as a JSON response. The URL could be anything that returns that known format doesn’t need to be Postman specific.
You’re dealing with a node script there and using that syntax just wouldn’t work that way.
It would be the same as if the node script did something else completely different that was nothing to do with Postman.
You can hardcode the value, store it as a variable, use something like the dotenv module as a config file, read the value from a system environment file but you can’t directly look into the JSON file in the same way.
You could read the JSON file with fs and extract out those values with vanilla JS but you can’t use {{..}} in the URL link because it would just be sending that complete string as the URL.
If you have feature requests and issues relating to the documentation, I would encourage you to raise them against the Newman repo so we can action those in the right place.
What I’m wondering is if we can access PM variables using the newman library?
I couldn’t tell if you answered that in your response so I can’t really post on the newman repo if that’s a feature you do in fact need.
Is the dotenv module a newman thing? I searched the newman repo, postman (community and documentation) and I couldn’t find any references to that.
If dotenv is a newman thing that should be documentated.
Thanks,
Rob
P.S. Here’s a snippet from newman documentation.
options.environment
One can optionally pass an environment file path or URL as string to this property and that will be used to read Postman Environment Variables from. This property also accepts environment variables as an object . Environment files exported from Postman App can be directly used here.
Optional
Type: object\|string
I want to do the thing in bold. Access the environment variables.
I work for Postman, which created Newman so…yes, I’m associated with it.
You cannot access Postman variables (which in this context are values in a JSON file) directly in that script, without reading the JSON file in someway to extract the data.
I believe there is a lack of JS/node knowledge happening here and what can and cannot be achieved within a node script.
The dotenv module is something that can be used alongside Newman as a library to abstract the way you reference certain config details.
The URL as a string would just be exactly what you’re doing with that URL to read the Collection file from the Postman API. That data set doesn’t need to come from the API, those can come from any public API that returns the environment values in that format.
This provides example of how you could reference variables in that newman run object:
Take a look at the Newman repo and raise these gaps on there, it’s a more targeted place that a thread on the community forum. It will be easier to group certain issues together as this thread is getting slightly pulled in multiple directions.
The iterationData value can be like it is in that example or that same array format in a local file and referenced in iterationData using require('data.json').
You could also use a URL, as a string which points to something that returns the data in that JSON format. Basically, that’s the format it needs to be in, how you reference that in the object is the thing that will be changing.
A CSV file can also be used as a source of data.
If the readme doesn’t make sense or the example is not giving you the necessary information you need to use the library, please do file an issue on the repository.