0

I'm a Java Developer and I'm starting to use Postman Runner and Newman. I have a test suite that need a token for the authorization header. This token is generated with a 3rd party service and I need to generate only one to run the entire test suite.

My question is if there is a way to run a script only once before the whole collection and not before each request as you can do with the Collection/Folder Pre-request script option.

My script will simply be something like:

const tokenServiceRequest = {...}
pm.sendRequest(tokenServiceRequest, (err, response)=>{
    pm.environment.set("token", response.json().token);
});

My intention is to get something similar to JUnit's @BeforeAll annotation. Is it possible with Postman Runner/Newman?

Disclaimer: Right now I'm using Newman as my Postman's free tier runner quota is already used, so I prefer a solution with Newman

Thanks in advance for your answer.

Alvaro Pedraza
  • 1,176
  • 6
  • 20
  • 44

0 Answers0