I am trying to replace a body with a pre-request script in Postman/newman. For some reason, it works in Postman but not in newman.
So I have this pre-request script:
// pm.environment.set("NEW_CONF", "FOO"); // testing
eval(pm.environment.get("getConfigFunc"));
getConfig().then((conf) => {
pm.environment.set("CONF_BACKUP", JSON.stringify(conf));
conf.General.Port = conf.General.Port + 1;
// pm.environment.set("NEW_CONF", "BAR"); // testing
pm.environment.set("NEW_CONF", JSON.stringify(conf));
});
In the body there is just {{NEW_CONF}}
. Postman replaces it, but in newman it does not work.
As you can see I added settings the variable NEW_CONF to FOO and later to BAR. FOO gets set and replaces the body, BAR is never set.
getConfig runs a pm.sendRequest which returns a promise with the resp.json() as return.
What am I doing wrong? Is newman not waiting for the promise? If so, is there a way to tell newman when to run the request after the promise returns?