How can i run my collection with newman, if i collect my variables from tests?

I have a collection where:

  • I create many users with different roles ,
  • I am updating them ,
  • login with each of them and
  • delete them at the end.

As the tokens are unique and change at each login , I am collecting them on each call and store in current variables.
everything is ok in POstman , I can run my collection , but as you know, I cannot use current values of my variables when I want to run monitors or run tests with Newman. My question is if someone can help me with some hints how can I solve this ?

Hi @anabd

Set them as a collection or environment level variable dynamically in your test tab;

Use to define a collection variable.
pm.collectionVariables.set("variable_key", "variable_value");

Use to define an environment variable in the currently selected environment.
pm.environment.set("variable_key", "variable_value");

You can use unset to remove a variable.
pm.environment.unset("variable_key");

Call them in a script like this;

//access a collection variable
pm.collectionVariables.get("variable_key");
//access an environment variable
pm.environment.get("variable_key");

Or in the API call using the {{variableName}} notation.

Read more about variables here

i am already using pm.environment.get(โ€œvariable_keyโ€);
i tried pm.collectionVariables.get(โ€œvariable_keyโ€) and still cannot run tests with monitor or Newman. i think i am doing something else wrong.
my variables doesnโ€™t have initial value , only the current one that is collected through each login test for each role.
I read on POstman documentation that current values are not stored into cloud and cannot be used via Newman. this is why i am asking how other people are using access tokens that need to be collected on each login in their automated tests.