Can't run k6-browser tests

Hello,

I’m having some troubles running a k6-browser test.

I’ve installed k6 with homebrew on macOS M1.
K6 version: k6 v0.45.0 ((devel), go1.20.5, darwin/arm64)

Test I try to run:

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/');
		page.screenshot({ path: 'screenshot.png' });
	} finally {
		page.close();
		browser.close();
	}
}

First I have a TS error: Module '"k6/experimental/browser"' has no exported member 'chromium'

When I try to run it, here is the output:

> K6_BROWSER_ENABLED=true pnpm start:prod
> node dist/main.js "--env" "prod" "--test" "browser"

Running test 1/1

          /\      |‾‾| /‾‾/   /‾‾/   
     /\  /  \     |  |/  /   /  /    
    /  \/    \    |     (   /   ‾‾\  
   /          \   |  |\  \ |  (‾)  | 
  / __________ \  |__| \__\ \_____/ .io

  execution: local
     script: dist/tests/browser-test.js
     output: -

  scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
           * default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)

ERRO[0000] Uncaught (in promise) GoError: launching browser: exec: no command
        at github.com/grafana/xk6-browser/browser.mapBrowserType.func2 (native)
        at browser_test_default (file:///Users/valentin/code/beescreens/apps/beeplace/tests/load-tests/dist/tests/browser-test.js:29:49(9))  executor=per-vu-iterations scenario=default

     data_received........: 0 B 0 B/s
     data_sent............: 0 B 0 B/s
     iteration_duration...: avg=8.2ms min=8.2ms med=8.2ms max=8.2ms p(90)=8.2ms p(95)=8.2ms
     iterations...........: 1   108.45987/s


running (00m00.0s), 0/1 VUs, 1 complete and 0 interrupted iterations
default ✓ [======================================] 1 VUs  00m00.0s/10m0s  1/1 iters, 1 per VU

I’m quite lost on this one, thanks a lot if you have an idea!

Hi @vkaelin, welcome to the forum! :wave:

In regards of the TS error. That is correct as currently chromium is not defined in TS types as it will be removed in the next release in favor of an exported browser property.

About the error:

ERRO[0000] Uncaught (in promise) GoError: launching browser: exec: no command

This usually happens when k6 browser can not find a local installation of Chrome/Chromium browser. Do you have Google Chrome installed in your machine?