Problems running k6 browser tests on wsl

Hi there,
I’m trying to run a simple k6 browser test within windows wsl.

But it can’t find the chromium browser, although it is installed. I also tried with google-chrome.

ls -l /usr/bin/chromium-browser /usr/bin/google-chrome
-rwxr-xr-x 1 root root 2408 Sep 18  2020 /usr/bin/chromium-browser
lrwxrwxrwx 1 root root   31 Oct  7 10:50 /usr/bin/google-chrome -> /etc/alternatives/google-chrome

Launching the browser from the same shell I launch k6 works!

The output from k6:

me@pc:~/code$ k6 run main.js

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

     execution: local
        script: main.js
        output: -

     scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
              * ui: 1 iterations shared among 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)


   ✓ checks...............: 0.00% ✓ 0           ✗ 0
     data_received........: 0 B   0 B/s
     data_sent............: 0 B   0 B/s
     iteration_duration...: avg=24.62µs min=24.62µs med=24.62µs max=24.62µs p(90)=24.62µs p(95)=24.62µs
     iterations...........: 1     3091.811338/s


running (00m00.0s), 0/1 VUs, 0 complete and 1 interrupted iterations
ui   ✗ [======================================] 1 VUs  00m00.0s/10m0s  1/1 shared iters
ERRO[0000] error building browser on IterStart: finding browser executable: k6 couldn't detect google chrome or a chromium-supported browser on this system at default (file:///home/xxx/code/main.js:21:16(0))

The script:

import { browser } from 'k6/browser';

export const options = {
  scenarios: {
    ui: {
      executor: 'shared-iterations',
      options: {
        browser: {
          type: 'chromium',
        },
      },
    },
  },
  thresholds: {
    checks: ['rate==1.0'],
  },
};

const BASE_URL = "http://localhost:3000";

export default async function () {

  const context = await browser.newContext();
  const page = await context.newPage();

  try {
    await page.goto(`${BASE_URL}/main/home`);
  } finally {
    await page.close();
  }
}

Hi @fastsyrup,

You can try to provide the path to the executable with the following environment variable:

K6_BROWSER_EXECUTABLE_PATH='the path to your executable' k6 run script.js

Hope it helps.

Hi thx, but still no luck.

The chrome-browser is installed at /usr/bin

fastsyrup@pc:~/code/goodnews-nextjs/perf_testing$ ls -l /usr/bin/chromium-browser
-rwxr-xr-x 1 root root 2408 Sep 18  2020 /usr/bin/chromium-browser

Starting the browser from the cmd line works.

But I stil get this error:

ERRO[0000] error building browser on IterStart: finding browser executable: k6 couldn't detect google chrome or a chromium-supported browser on the given path: /usr/bin/chromium-browser at default (file:///home/fastsyrup/code/goodnews-nextjs/perf_testing/main.js:21:16(0))

See here:

fastsyrup@pc:~/code/goodnews-nextjs/perf_testing$ export K6_BROWSER_EXECUTABLE_PATH="/usr/bin/chromium-browser" && k6 run main.js

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

     execution: local
        script: main.js
        output: -

     scenarios: (100.00%) 1 scenario, 1 max VUs, 1m0s max duration (incl. graceful stop):
              * contacts: 1 looping VUs for 30s (gracefulStop: 30s)


     data_received........: 0 B 0 B/s
     data_sent............: 0 B 0 B/s
     iteration_duration...: avg=20.82µs min=20.82µs med=20.82µs max=20.82µs p(90)=20.82µs p(95)=20.82µs
     iterations...........: 1   4285.738776/s


running (0m00.0s), 0/1 VUs, 0 complete and 1 interrupted iterations
contacts ✗ [--------------------------------------] 1 VUs  00.0s/30s
ERRO[0000] error building browser on IterStart: finding browser executable: k6 couldn't detect google chrome or a chromium-supported browser on the given path: /usr/bin/chromium-browser at default (file:///home/fastsyrup/code/goodnews-nextjs/perf_testing/main.js:21:16(0))

I found the error, k6 was installed on wsl through snap, and somehow that doesn’t work. I removed and installed it normally. Now everything is fine.

Thx!

1 Like