Reputation: 41
I am sending a request via Postman that requires Basic Auth. I want to save the value of the basic auth in a variable so i will be able to use it again.
In the request I am sending I'm providing user name and password (basic), and it is translated into authorization header. i want to take the value sent in the request header, and save it.
how can i take the value from the request header and place in a env variable, all in Test Script?
Upvotes: 2
Views: 7398
Reputation: 3721
In the test
You can write something like that after creating global variable
you can go to your service
that provides you the value and add the test and set the result in the global variable
.
For example for me the login service
provides me a token
so after testing and getting the new token
i set this in the global variable token
var jsonData = JSON.parse(responseBody);
if (jsonData && jsonData.result && jsonData.result.session) {
postman.setEnvironmentVariable("token", jsonData.result.session.token);
}
Upvotes: 2