Can't run browser tests with K6_BROWSER_ENABLED=true k6 run script.js

The term ‘K6_BROWSER_ENABLED=true’ is not recognized as the name of a cmdlet, function, script file, or operable program.

I receive the above error when i run in terminal “K6_BROWSER_ENABLED=true k6 run script.js”
I don’t know what I have to do with this error to can run the test.
I have to install some dependencies for browser tests maybe?

Here is the test:

import { chromium } from ‘k6/experimental/browser’;

export default async function () {
const browser = chromium.launch({
headless: false,
timeout: ‘60s’, // Or whatever time you want to define
});
const page = browser.newPage();

try {
await page.goto(‘https://test.k6.io/’, { waitUntil: ‘networkidle’ });
page.screenshot({ path: ‘screenshot.png’ });
} finally {
page.close();
browser.close();
}
}

Hi @MRadu11 ! :wave: Welcome to the forum!

Which O.S. are you running k6 on? Which k6 version are you using?
Can you paste here the exact cmd you are executing?

Thanks.

My O.S is Windows 10, k6 is at version v0.43.1

Hi @MRadu11 ,

In Windows O.S. you should set the environment variable such as:

C:\k6> set "K6_BROWSER_ENABLED=true" && k6 run script.js

Thank you, with this command “set “K6_BROWSER_ENABLED=true” && k6 run script.js”, I can run, but just in the command prompt.
i want to run in vs code terminal-powershell, must be possible that…

That’s because the terminal in your VSCode is Windows PowerShell. In that case this should work:

PS C:\k6> $env:K6_BROWSER_ENABLED=true ; k6 run script.js

in this case, i receive the same error like first.

Have you tried wrapping true in '' such as:

PS C:\k6> $env:K6_BROWSER_ENABLED='true' ; k6 run script.js

?