Browser testing with k6 - browser is not launching

Hi everyone!! I’m new to k6. I just tried implementing the below code but I am getting
ERRO[0000] Uncaught (in promise) TypeError: Cannot read property ‘launch’ of undefined or null at file:///D:/K6/K6_REPO/FRONT_END_PERFORMANCE_TEST/Specs/sampleTest.js:6:14(3) executor=per-vu-iterations scenario=default
How to solve this, what am I missing???
Browser is not launching


Hi @umaisummer!

Try it this way:

import {browser} from 'k6/experimental/browser';
import {sleep} from 'k6';

export const options = {
  scenarios: {
    perftest: {
      executor: 'per-vu-iterations',
      options: {
        browser: {
          type: 'chromium',
        },
      },
    },
  },
}

export  default async function(){
  const page = browser.newPage();
  try{
    const response = await page.goto('https://testorg.stotte.no',{waitUntil:'networkidle'});
    sleep(4);
    console.log('Status Code:', response.status());
  }finally{
    page.close();
  }
}

If you want to run it with visible browser, just run with K6_BROWSER_HEADLESS=false k6 run script.js

1 Like

Hey @umaisummer , welcome to the forum! :wave:

@bandorko is right! That is the correct syntax for the latest version. Give it a try.

The syntax that you were using in your implementation corresponds to a previous version (<v0.46). k6 v0.46 introduced a few breaking changes for the browser module, you can see more details in this migration guide.

1 Like