Update environment variable in Postman using Newman












0















I'm using Newman and Postman to test a website.



My Newman command construction looks like:



newman run
"https://api.getpostman.com/collections/{collection_id}?apikey={my_postman_api_key}"
--environment "https://api.getpostman.com/environments/{environment_id}?apikey={my_postman_api_key}"
--export-environment "https://api.getpostman.com/environments/{environment_id}?apikey={my_postman_api_key}"
--insecure


This all works fine but my environment values don't update after the Newman run.



In my request, I use a Pre-request Script to update the value:



var mail = pm.environment.get("mail_randomizer");
pm.environment.set("mail_randomizer", Number(mail) + 1);


After sending this request in Postman, the value for the mail_randomizer variable has gone up by 1 but after running the request using Newman, it doesn't work.



How can I export the environment correctly in Newman?










share|improve this question

























  • What do you mean by "it doesn't work"? What happens? Can you provide any images of what you're seeing? The Newman environment export command looks right to me.

    – Danny Dainton
    Aug 16 '18 at 14:02











  • The variable in the environment doesn't update

    – Eugene Truuts
    Aug 16 '18 at 14:04











  • Yeah I get that...What happens to the query? Did it run with the updated value but not export the new value? Does any of the tests that you may have fail? Need more details to know what's going on.

    – Danny Dainton
    Aug 16 '18 at 14:08













  • Next query will not work because my value should be unique. So, I receive a red failed assertion in Newman log. But if I will re-send this request in Postman, my variable will be successfully updated and will be available to the Newman test. The first test will be passed because my value will be still unique, but after that, the next Newman test will fail because my value will not update in the environment.

    – Eugene Truuts
    Aug 16 '18 at 14:17











  • @EugeneTruuts Can you share the collection in which this is happening? Retract any sensitive information. (Replace url's with postman-echo.com if you need)

    – Sivcan Singh
    Aug 17 '18 at 7:13


















0















I'm using Newman and Postman to test a website.



My Newman command construction looks like:



newman run
"https://api.getpostman.com/collections/{collection_id}?apikey={my_postman_api_key}"
--environment "https://api.getpostman.com/environments/{environment_id}?apikey={my_postman_api_key}"
--export-environment "https://api.getpostman.com/environments/{environment_id}?apikey={my_postman_api_key}"
--insecure


This all works fine but my environment values don't update after the Newman run.



In my request, I use a Pre-request Script to update the value:



var mail = pm.environment.get("mail_randomizer");
pm.environment.set("mail_randomizer", Number(mail) + 1);


After sending this request in Postman, the value for the mail_randomizer variable has gone up by 1 but after running the request using Newman, it doesn't work.



How can I export the environment correctly in Newman?










share|improve this question

























  • What do you mean by "it doesn't work"? What happens? Can you provide any images of what you're seeing? The Newman environment export command looks right to me.

    – Danny Dainton
    Aug 16 '18 at 14:02











  • The variable in the environment doesn't update

    – Eugene Truuts
    Aug 16 '18 at 14:04











  • Yeah I get that...What happens to the query? Did it run with the updated value but not export the new value? Does any of the tests that you may have fail? Need more details to know what's going on.

    – Danny Dainton
    Aug 16 '18 at 14:08













  • Next query will not work because my value should be unique. So, I receive a red failed assertion in Newman log. But if I will re-send this request in Postman, my variable will be successfully updated and will be available to the Newman test. The first test will be passed because my value will be still unique, but after that, the next Newman test will fail because my value will not update in the environment.

    – Eugene Truuts
    Aug 16 '18 at 14:17











  • @EugeneTruuts Can you share the collection in which this is happening? Retract any sensitive information. (Replace url's with postman-echo.com if you need)

    – Sivcan Singh
    Aug 17 '18 at 7:13
















0












0








0








I'm using Newman and Postman to test a website.



My Newman command construction looks like:



newman run
"https://api.getpostman.com/collections/{collection_id}?apikey={my_postman_api_key}"
--environment "https://api.getpostman.com/environments/{environment_id}?apikey={my_postman_api_key}"
--export-environment "https://api.getpostman.com/environments/{environment_id}?apikey={my_postman_api_key}"
--insecure


This all works fine but my environment values don't update after the Newman run.



In my request, I use a Pre-request Script to update the value:



var mail = pm.environment.get("mail_randomizer");
pm.environment.set("mail_randomizer", Number(mail) + 1);


After sending this request in Postman, the value for the mail_randomizer variable has gone up by 1 but after running the request using Newman, it doesn't work.



How can I export the environment correctly in Newman?










share|improve this question
















I'm using Newman and Postman to test a website.



My Newman command construction looks like:



newman run
"https://api.getpostman.com/collections/{collection_id}?apikey={my_postman_api_key}"
--environment "https://api.getpostman.com/environments/{environment_id}?apikey={my_postman_api_key}"
--export-environment "https://api.getpostman.com/environments/{environment_id}?apikey={my_postman_api_key}"
--insecure


This all works fine but my environment values don't update after the Newman run.



In my request, I use a Pre-request Script to update the value:



var mail = pm.environment.get("mail_randomizer");
pm.environment.set("mail_randomizer", Number(mail) + 1);


After sending this request in Postman, the value for the mail_randomizer variable has gone up by 1 but after running the request using Newman, it doesn't work.



How can I export the environment correctly in Newman?







api testing postman qa newman






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 16 '18 at 13:54









Danny Dainton

3,8812820




3,8812820










asked Aug 16 '18 at 13:02









Eugene TruutsEugene Truuts

508




508













  • What do you mean by "it doesn't work"? What happens? Can you provide any images of what you're seeing? The Newman environment export command looks right to me.

    – Danny Dainton
    Aug 16 '18 at 14:02











  • The variable in the environment doesn't update

    – Eugene Truuts
    Aug 16 '18 at 14:04











  • Yeah I get that...What happens to the query? Did it run with the updated value but not export the new value? Does any of the tests that you may have fail? Need more details to know what's going on.

    – Danny Dainton
    Aug 16 '18 at 14:08













  • Next query will not work because my value should be unique. So, I receive a red failed assertion in Newman log. But if I will re-send this request in Postman, my variable will be successfully updated and will be available to the Newman test. The first test will be passed because my value will be still unique, but after that, the next Newman test will fail because my value will not update in the environment.

    – Eugene Truuts
    Aug 16 '18 at 14:17











  • @EugeneTruuts Can you share the collection in which this is happening? Retract any sensitive information. (Replace url's with postman-echo.com if you need)

    – Sivcan Singh
    Aug 17 '18 at 7:13





















  • What do you mean by "it doesn't work"? What happens? Can you provide any images of what you're seeing? The Newman environment export command looks right to me.

    – Danny Dainton
    Aug 16 '18 at 14:02











  • The variable in the environment doesn't update

    – Eugene Truuts
    Aug 16 '18 at 14:04











  • Yeah I get that...What happens to the query? Did it run with the updated value but not export the new value? Does any of the tests that you may have fail? Need more details to know what's going on.

    – Danny Dainton
    Aug 16 '18 at 14:08













  • Next query will not work because my value should be unique. So, I receive a red failed assertion in Newman log. But if I will re-send this request in Postman, my variable will be successfully updated and will be available to the Newman test. The first test will be passed because my value will be still unique, but after that, the next Newman test will fail because my value will not update in the environment.

    – Eugene Truuts
    Aug 16 '18 at 14:17











  • @EugeneTruuts Can you share the collection in which this is happening? Retract any sensitive information. (Replace url's with postman-echo.com if you need)

    – Sivcan Singh
    Aug 17 '18 at 7:13



















What do you mean by "it doesn't work"? What happens? Can you provide any images of what you're seeing? The Newman environment export command looks right to me.

– Danny Dainton
Aug 16 '18 at 14:02





What do you mean by "it doesn't work"? What happens? Can you provide any images of what you're seeing? The Newman environment export command looks right to me.

– Danny Dainton
Aug 16 '18 at 14:02













The variable in the environment doesn't update

– Eugene Truuts
Aug 16 '18 at 14:04





The variable in the environment doesn't update

– Eugene Truuts
Aug 16 '18 at 14:04













Yeah I get that...What happens to the query? Did it run with the updated value but not export the new value? Does any of the tests that you may have fail? Need more details to know what's going on.

– Danny Dainton
Aug 16 '18 at 14:08







Yeah I get that...What happens to the query? Did it run with the updated value but not export the new value? Does any of the tests that you may have fail? Need more details to know what's going on.

– Danny Dainton
Aug 16 '18 at 14:08















Next query will not work because my value should be unique. So, I receive a red failed assertion in Newman log. But if I will re-send this request in Postman, my variable will be successfully updated and will be available to the Newman test. The first test will be passed because my value will be still unique, but after that, the next Newman test will fail because my value will not update in the environment.

– Eugene Truuts
Aug 16 '18 at 14:17





Next query will not work because my value should be unique. So, I receive a red failed assertion in Newman log. But if I will re-send this request in Postman, my variable will be successfully updated and will be available to the Newman test. The first test will be passed because my value will be still unique, but after that, the next Newman test will fail because my value will not update in the environment.

– Eugene Truuts
Aug 16 '18 at 14:17













@EugeneTruuts Can you share the collection in which this is happening? Retract any sensitive information. (Replace url's with postman-echo.com if you need)

– Sivcan Singh
Aug 17 '18 at 7:13







@EugeneTruuts Can you share the collection in which this is happening? Retract any sensitive information. (Replace url's with postman-echo.com if you need)

– Sivcan Singh
Aug 17 '18 at 7:13














1 Answer
1






active

oldest

votes


















0














create



.env : environment variable let's say



url = http://localhost:3000/api



.env.example should be



url =



in your test call :



var local-url = process.env.url;



add in your package json



npm install dotenv






share|improve this answer








New contributor




Shahin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • Please edit your post and fix the formatting. Code or shell commands for any OS should be either indented with four spaces, or pre- and postfixed with three backticks (`)

    – Zoe
    Jan 19 at 20:06













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51877735%2fupdate-environment-variable-in-postman-using-newman%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














create



.env : environment variable let's say



url = http://localhost:3000/api



.env.example should be



url =



in your test call :



var local-url = process.env.url;



add in your package json



npm install dotenv






share|improve this answer








New contributor




Shahin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • Please edit your post and fix the formatting. Code or shell commands for any OS should be either indented with four spaces, or pre- and postfixed with three backticks (`)

    – Zoe
    Jan 19 at 20:06


















0














create



.env : environment variable let's say



url = http://localhost:3000/api



.env.example should be



url =



in your test call :



var local-url = process.env.url;



add in your package json



npm install dotenv






share|improve this answer








New contributor




Shahin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • Please edit your post and fix the formatting. Code or shell commands for any OS should be either indented with four spaces, or pre- and postfixed with three backticks (`)

    – Zoe
    Jan 19 at 20:06
















0












0








0







create



.env : environment variable let's say



url = http://localhost:3000/api



.env.example should be



url =



in your test call :



var local-url = process.env.url;



add in your package json



npm install dotenv






share|improve this answer








New contributor




Shahin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.










create



.env : environment variable let's say



url = http://localhost:3000/api



.env.example should be



url =



in your test call :



var local-url = process.env.url;



add in your package json



npm install dotenv







share|improve this answer








New contributor




Shahin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this answer



share|improve this answer






New contributor




Shahin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









answered Jan 18 at 17:20









ShahinShahin

93




93




New contributor




Shahin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Shahin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Shahin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













  • Please edit your post and fix the formatting. Code or shell commands for any OS should be either indented with four spaces, or pre- and postfixed with three backticks (`)

    – Zoe
    Jan 19 at 20:06





















  • Please edit your post and fix the formatting. Code or shell commands for any OS should be either indented with four spaces, or pre- and postfixed with three backticks (`)

    – Zoe
    Jan 19 at 20:06



















Please edit your post and fix the formatting. Code or shell commands for any OS should be either indented with four spaces, or pre- and postfixed with three backticks (`)

– Zoe
Jan 19 at 20:06







Please edit your post and fix the formatting. Code or shell commands for any OS should be either indented with four spaces, or pre- and postfixed with three backticks (`)

– Zoe
Jan 19 at 20:06




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51877735%2fupdate-environment-variable-in-postman-using-newman%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Liquibase includeAll doesn't find base path

How to use setInterval in EJS file?

Petrus Granier-Deferre