How to rewrite variables in Newman? I have a file with my environment variables that are rewritten after a request is executed, everything works in Postman (RUN FOLDER), but in Newman all tests crash. Many of my variables do not have initial values, they only acquire them when a test passes. For example there is a POST request that adds a user, the body of the response will return to me:
{
"id": null,
"result": {
"id": "c9497eb1-e4ea-47f0-a00e-a46cf8ef07a7"
},
"success": true
}
I take the value of the ID, and override the variable with the following command:
var jsonData = pm.response.json();
pm.environment.set('newUserId', jsonData.result.id);
When running Newman, everything crashes. Please help, if you would be so kind.
What key should I use when starting Newman? Or how to achieve positive results in NEWMAN to be like in Postman, is there such an option for processing variables?
Many tests drops when I use env value in URL path, like
https://some-url/check/{createdUserId}.
You can export also environment variable too. The 'newman' running no problem if using exported
environment variableHow to export environment variable.
Select 'environment quick look' - right/top icon in Postman
Select 'edit' menu
Select See more action (...)
Run newman with exported environment.json
Demo
#1 running a local API server for adding user and getting user
#2 postman call
#3 running collection
#4 newman running
#1 running a local API server
Save as 'server'js'
Install dependencies
Running server
#2 postman call
Create User 1 and get User 1, checked user information (name and email) Key is using
user-idenvironment variable for POST (Adding)/GET(Getting) user pair.If not matched Adding user/ Getting user, something wrong.
POST returned
GET user
Response
It can confirmed created user and get user is same or not by calling GET with
uuidThis format
Create User1
Teststab for adding userPOST call
Body
Get User1
Teststab for adding userGET call
Add user 2 with different user information
#3 running collection on Postman
#4
newmanrunning on terminal