Skip to content
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

Variable handling is not the same in request builder and runner #6352

Closed
klemens-u opened this issue Apr 24, 2019 · 7 comments
Closed

Variable handling is not the same in request builder and runner #6352

klemens-u opened this issue Apr 24, 2019 · 7 comments

Comments

@klemens-u
Copy link

Situation:

Environment variable: "status_code_default" = 200

Collection Test (Collection -> Edit -> Tests):

statusCodeDefault = Number(pm.variables.get("status_code_default"));
pm.test("Status code is " + statusCodeDefault, function () {
    pm.response.to.have.status(statusCodeDefault);
});

So this adds a default test to every request checking if the status code = 200.

Now for a specific request we want to override the default value:
Request -> Pre-request Script: pm.variables.set("status_code_default", 400);

This way we can assert that the request expects code 400.

This works fine in the request builder.

Problem: it does not work for subsequent request in runner. The default value from the environment is not loaded before the next request. Therefore the last custom value leaks into the next request.
For example for the subsequent request I expect code 200 again, but in the runner it is still set to code 400.

Postman v7.0.9
Ubuntu 16.04

@m3dbedb
Copy link

m3dbedb commented May 27, 2019

This should not work at all. By using pm.variables.set you address to collection variables, and they are not allowed to be modified while collection run. They are to be pre-defined and you may only read them.
pm.variables.set is not allowed.
https://hghltd.yandex.net/yandbtm?lang=en&fmode=inject&tm=1558942838&tld=ru&la=1558537344&text=pm.variables.has&url=https%3A%2F%2Flearning.getpostman.com%2Fdocs%2Fpostman%2Fenvironments_and_globals%2Fvariables&l10n=ru&mime=html&sign=f2b52e5a32e22d9645e9a51fdadccdc0&keyno=0

Defining collection variables
Collection variables can be defined by editing the collection details. Click ellipsis (...) next to the collection name, and select “Edit” to open the EDIT COLLECTION modal. Select the Variables tab to add and edit collection variables . You can also define collection variables when creating the collection.

@klemens-u
Copy link
Author

@m3dbedb: what method would you propose for the described use case?

Similar behaviour in both request builder and runner would be very desireable.

@m3dbedb
Copy link

m3dbedb commented May 27, 2019

I use environmet variable to store test stand settings, and globals for temporary data (I understand that it sounds odd, but I keep environment parameters in environment variables, and it is consistent).

@klemens-u
Copy link
Author

@m3dbedb sorry, but what do you mean by that? How does that help with the example above for a default test case & default value?

@m3dbedb
Copy link

m3dbedb commented May 27, 2019

@klemens-u, in my previous post edit I missed issue and passed wrong advice.

@klemens-u
Copy link
Author

@m3dbedb ok, no problem :-)

@shamasis
Copy link
Member

This is intended behaviour of Postman. I suggest that you unset that variable right after testing so that any of them set in previous scripts do not affect the next. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants