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();
    const response = await page.goto('',{waitUntil:'networkidle'});
    console.log('Status Code:', response.status());

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

The syntax is not working for me now. It says
K6_BROWSER_HEADLESS=false : The term ‘K6_BROWSER_HEADLESS=false’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At line:1 char:1

  • K6_BROWSER_HEADLESS=false k6 run script.js
  •   + CategoryInfo          : ObjectNotFound: (K6_BROWSER_HEADLESS=false:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException

Is there any new syntax to run it with visible browser?

Hi @saivignesh0303,

I believe you’re running tests on Windows. Did you try the following:

set "K6_BROWSER_HEADLESS=false" && k6 run script.js

Yes @inancgumus I am running tests on windows and I tried that command too and I received the following error

At line:1 char:33

  • set “K6_BROWSER_HEADLESS=false” && k6 run script.js
  •                             ~~

The token ‘&&’ is not a valid statement separator in this version.
+ CategoryInfo : ParserError: (:slight_smile: , ParentContainsErrorRecordException
+ FullyQualifiedErrorId : InvalidEndOfLine

Hi @saivignesh0303 !

Could you try with:

$Env:K6_BROWSER_HEADLESS='false' ; k6 run script.js

Thank you, @bandorko. It worked. Thanks a lot again. Could you please tell me what are the selectors supported by the xk6 browser to select an element in a web page like CSS selector, XPath,… that could be used with page.locator()?

According to this document: Selecting elements it supports css and xpath selectors