GlobalThis variable using for Multiple scenarios

Hi ,
I am trying to run multiple scenarios and trying to access variables in the csv file using globalthis variables.

I see that only the first testcase values are read and the second test gets undefined value. And also, am using two different csv files for both.

First test

export function testCase03_Baseline(){
  globalThis.chosenUser1 = users[(vu.idInTest - 1)]

  if (vuToken === undefined) {
    vuToken = getToken(users[ - 1].Email, users[ - 1].Password)


Second test

export function testCase02_Baseline1(){
  globalThis.chosenUser2 = users[(vu.idInTest - 1)]

  if (vuToken === undefined) {
    vuToken = getToken(users[ - 1].Email, users[ - 1].Password)


Both LoadPage call different functions and some of the end points need values from csv files.

The login works correctly but the second testcase loadpage end point gets undefined.
And these variables are declared chooseuser1 and chosenuser2 are declared in the base login page and Imported.

Hi @jayareva :wave:

Could you please post an example that demonstrates your configuration too?

My understanding is that those two test cases you showed are executed as part of different scenarios, but I’d like to make sure of it before proceeding with a more specific answer :bowing_man:

Yes, these two are different scenarios and i am calling two different functions.


export function JDMBaseline() {

export function pricingProjectBaseline() {

export function jobsBseline() {

export function peerAutomatch() {



export function testCase02_JDMBaseline() {
  globalThis.chosenUser = users1[(vu.idInTest - 1)] if (vuToken === undefined) {
  //getToken is from baselong.js
  vuToken = getToken(users1[ - 1].Email, users1[ - 1].Password) 

//JDM save job is calling  jdm.js file


export function JDM_SaveJob() {
  //let response
  let jobFamily2=`${globalThis.chosenUser.jobFamily}`
    `page_2 - JDM_SaveJob`,
    function () {
= http.get(`${baseUri}/JobDescription(${globalThis.chosenUser.JobID})/Default.GetDetail`

And similarily for the other testcase defining the global variable and calling another function for the endpoint where i am passing the global variable to read from the csv file


If my understanding of your setup is correct, I believe what you’re experiencing is due to scenarios being run in isolation from each other. k6 currently does not allow sharing state between scenarios, neither through global variables, nor through the globalThis object as you’ve attempted here.

We’re aware of that limitation, and although providing a solution that offers a good developer experience is not trivial, it is on our radar, and we’re considering options to solve it in the future.

The most immediate workaround I would suggest is if you are able to use the xk6 extension-system, you could either use the xk6-kv extension which offers access to shared key-value store, or even use the k6/experimental/redis module if you are able to run or access a redis server, and store the state you intend to share there.

Let me know if that helped :bowing_man:

But in my case, I am not using the same csv file and the login works fine, but I see the other variables in both csv files are having issues.

Hey @jayareva :wave:

To avoid misunderstandings, could you please put together a minimal script reproducing your test setup, that I could copy/paste locally and run to reproduce the issue you’re experiencing please?

I have a feeling I might be missing something :bowing_man:

1 Like