Browser testing with k6

Hi everyone!! I’m new to k6. I just tried implementing the below code but I am getting ERRO[0000] GoError: To run browser tests set env var K6_BROWSER_ENABLED=true
at*InitContext).Require-fm (native)
at file:///C:/k6-learning/script.js:1:0(12) hint=“script exception”.
How to solve this, what am I missing???

Hi @Sreyaa,

The environment variable should be set when running the k6 command. Please see the following steps to solve the issue.

  1. Please remove these lines from your script:

    const res = `${____ENV.K6_BROWSER_ENABLED}`;
    res = true;
  2. Then run the k6 command with the K6_BROWSER_ENABLED environment variable set:

    K6_BROWSER_ENABLED=true k6 run script.js

Please let us know how it goes.


PS: If you’re on a Windows machine, you might also want to try the following:

set "K6_BROWSER_ENABLED=true" && k6 run script.js

No, It is showing K6_BROWSER_ENABLED=true : The term ‘K6_BROWSER_ENABLED=true’ 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

But, it is working fine after I remove these lines(const res = ${____ENV.K6_BROWSER_ENABLED};
res = true;) and run it with this command
k6 run --env K6_BROWSER_ENABLED=true script.js