-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The environment variable set in sendRequest (prerequest script) during Newman execution not accessible in testscript. Works in Collection Runner and Postman. #1825
Comments
@slavenantic Can you share a sample collection and data file used to reproduce this issue? |
Is there any chance to send these things to you via email? |
@slavenantic You can attach the collection JSON file(minus the sensitive details) in GitHub comment itself. |
Here they go. sample.postman_collection.zip |
@slavenantic Thanks for sharing the collection but Its hard to reproduce the issue using this collection. Since it has more than 50 requests as well as hitting a private endpoint. Can you share the command used to run Newman? |
There you go: |
@slavenantic Can you try executing the attached collection using: $ newman run NEWMAN-1825.postman_collection.json -d allImageIds_nl.json Modified your scripts to reproduce the issue locally. The environment variable |
I can still reproduce the same issue with your modifications (I don't see any relevant changes in your collection). The variable is still set at the same place in pre-request script. What changes did you make actually? |
@slavenantic I just changed the request endpoint to an echo server to execute the collection. Are tests failing for you? Can you try updating Newman to the latest version and check if the issue still persists? |
I am still having the same issue, even after newman update to 4.3.1. |
@slavenantic As discussed above, I am not able to reproduce this issue. |
@codenirvana I am facing the same issue, I have uploaded the collection file, it has two requests one that works, one that doesn't. I want to update the collection variable (or any variable) according to a few criteria and the status of the request , Please see the request description to know which works and which doesn't |
@praveendvd you are updating the "projectid" variable in a promise in the test script of the second request, which is taking some time to execute. As promises are executed asynchronously, the getter of the "projectid" variable in (the last line of the test script) is getting the old value of the variable, before the execution of the promise. That's the reason why you are getting the old value for the "projectid" variable. |
@codenirvana It might be the same case with @slavenantic too. I have a question for you. Are the Postman sandboxes strictly sequential or they can run in parallel also? If they run in parallel, then some of the variables may not get assigned/updated in time(before the next sandbox tries to access that variable) if a request sent by sendRequest() in the first sandbox takes a long time to execute. |
@csk1827 yes that's the issue I was able to fix it
|
Sandboxes are supposed to be executed serially. The way sandbox waits for script execution completion is to look for timers to end. Since promises are not timers, they aren’t waited for. To wait for it, we need to deprecate till node v6 (and maybe 8) and use async_hooks to wait for timers. cc @codenirvana @coditva |
Closing as duplicate of postmanlabs/postman-app-support#5606 |
newman -v
): 4.2.2`//
let id1 = 19;
let isDataDriven = pm.iterationData.get("Input");
let id2 = 0;
if (isDataDriven) {
id1 = pm.iterationData.get("Input").id1;
id2 = pm.iterationData.get("Input").id2;
pm.environment.set('id2', id2);
}
var requestUrl = pm.environment.get("environment") + '/resource/' + id1;
var options = { method: 'GET', url: requestUrl };
pm.sendRequest(options, function (error, response) {
if (error) throw new Error(error);
var jsonData = response.json();
pm.environment.set('responseTime', response.responseTime);
if (id2 !== 0) {
id2 = jsonData.id2;
pm.environment.set('id2', id2);
}
});`
6. Sample collection, and auxiliary files (minus the sensitive details):
7. Screenshots (if applicable):
The text was updated successfully, but these errors were encountered: