Skip to content
Advertisement

Validating Oauth credentials in K6 load test script

I am trying to grab a token and pass it into the GET requests.

The below works, but it’s grabbing a token every single time a request runs. Ideally I want to grab it once per run and pass it to the requests.

Any ideas on how to make that happen from the below code?

JavaScript

Advertisement

Answer

In k6 lifecycle there are 4 stages. You need to use the proper one for your need.

Get exactly one token for the whole test

Can use setup function

JavaScript

Get one token for every VU (Virtual User)

Can use “init code.”

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement