apideck-libraries / postman-to-k6

Converts Postman collections to k6 script code
https://npmjs.com/package/@apideck/postman-to-k6
Apache License 2.0
233 stars 24 forks source link

K6 setup() #46

Open thim81 opened 2 years ago

thim81 commented 2 years ago

Feature: Provide a converter option to insert custom K6 "setup()" logic, that will be injected during conversion.

Reasoning: K6 supports a life cycle: https://k6.io/docs/using-k6/test-life-cycle/ The package already supports the “pre-request” functionality from Postman, but it feels that “setup()” and “teardown()” is not a concept that exists in Postman, and it serves more the K6 execution.

Approach: Provide a file reference as a --k6-setup CLI parameter, that will be take the content of the file and insert it in the generated K6 script.

aaroncampecino commented 1 year ago

Hi @thim81 ,

Sorry for being a complete newbie.

Given I have multiple requests that required authentication. And I execute the script with --separate true flag. Then configured setup function that returns the correct JWT token.

How can I pass the access_token to each file requests/SAMPLE_FILE.js to be added to the headers config?

export function setup() {
  //returns Bearer TEST_TOKEN
  return authenticateUsingOkta();
}

export default function(data) {
  group("Test", function() {
    postman[Request]("Test name");
  });
}