Migrate to k6 0.46.0

aswHi,

Can someone please instruct me on how to convert this section:

export const options = {
  insecureSkipTLSVerify: true,
  thresholds: {
    checks: ["rate==1.0"]
  },

  scenarios: {
    'use-all-the-data': {
      executor: 'shared-iterations',
      vus: 1,
      iterations: iterationsFromDataSource,
      maxDuration: '300s',
    },
  }
}

To convert and support the latest version.
I’ve tried to convert to something like this but it doesn’t seem to be working.

export const options = {
  insecureSkipTLSVerify: true,
  thresholds: {
    checks: ["rate==1.0"]
  },

  scenarios: {
    'use-all-the-data': {
      executor: 'shared-iterations',
      vus: 1,
      iterations: iterationsFromDataSource,
      maxDuration: '300s',
    },
    ui: {
      executor: 'shared-iterations',
      options: {
        browser: {
          type: 'chromium',
        },
      },
    },
  }
}

I’m getting the following error using the new version 0.46:
**Uncaught (in promise) GoError: browser not found in registry. make sure to set browser type option in scenario definition in order to use **
the browser module

I tried to change it to the following:
export const options = {
insecureSkipTLSVerify: true,
thresholds: {
checks: [“rate==1.0”]
},
scenarios: {
‘use-all-data’: {
executor: ‘shared-iterations’,
vus: 10,
maxDuration: ‘300s’,
iterations: iterationsFromDataSource,
options: {
browser: {
type: ‘chromium’,
},
},
},
}
}

But when I’m passing env variable K6_ITERATIONS i’m getting the error:

ERRO[0002] Uncaught (in promise) GoError: browser not found in registry. make sure to set browser type option in scenario definition in order to use the browser module

I need to pass it as I need to override this setting when running it from a pipeline. The user chooses the number of iterations so I need to override the code values.

Hi @idosegal,

As you’ve found out, unfortunately the K6_ITERATIONS env var doesn’t work with scripts that use the browser module. The reason is that using K6_ITERATIONS actually recreates a new scenario under-the-hood which replaces the one that is in the script. This new scenario is not enabled to work with the browser module.

If i’ve understood your use case correctly, then there is a workaround which is to use a custom env var. A detailed answer can be found here. A quick example is here where I’ve created my own env var ITERATIONS:

export const options = {
  scenarios: {
    ui: {
      executor: 'shared-iterations',
      iterations: __ENV.ITERATIONS,
      options: {
        browser: {
            type: 'chromium',
        },
      },
    },
  },
}

To run the test you would supply the env var when you run the script:

ITERATIONS=5 k6 run test.js

or

k6 run --env ITERATIONS=5 test.js

Hope this helps.

Cheers,
Ankur

1 Like