K6 browser Github Action error building browser: no command

I’m trying to run some K6 browser tests in Github Actions but getting an error:

time="2023-12-13T10:08:56Z" level=error msg="error building browser on IterStart: launching browser: exec: no command at browserFunction (file:///github/workspace/test.js:28:7(0))"

I can run http tests (ie. not using the browser) just fine in the Action and I can confirm that the browser test runs fine locally

The code I’m using is K6 boilerplate. Test file:

import { browser } from "k6/experimental/browser";
import { check, sleep } from "k6";
import http from "k6/http";

export const options = {
  scenarios: {
    ui: {
      executor: "shared-iterations",
      exec: "browserFunction",
      options: {
        browser: {
          type: "chromium",
        },
      },
    },
    // http: {
    //   executor: "constant-vus",
    //   exec: "httpFunction",
    //   vus: 10,
    //   duration: "5s",
    // },
  },
  thresholds: {
    checks: ["rate==1.0"],
  },
};

export async function browserFunction() {
  const context = browser.newContext();
  const page = context.newPage();

  try {
    await page.goto("https://test.k6.io/my_messages.php");

    page.locator('input[name="login"]').type("admin");
    page.locator('input[name="password"]').type("123");

    const submitButton = page.locator('input[type="submit"]');

    await Promise.all([page.waitForNavigation(), submitButton.click()]);

    check(page, {
      header: (p) => p.locator("h2").textContent() == "Welcome, admin!",
    });
  } finally {
    page.close();
  }
}

export async function httpFunction() {
  const res = http.get("https://httpbin.test.k6.io/");
  check(res, { "status was 200": (r) => r.status == 200 });
  sleep(1);
}

Action file:

name: Main Workflow
on: [push]
jobs:
  build:
    name: Run k6 test
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Run k6 local test
        uses: grafana/k6-action@v0.3.1
        with:
          filename: test.js

I have tested this on two machines in separate Github repos respectively (work and personal) but using the same Github account, with the same error occuring. Is K6 unable to find the browser when running in the workflow?

Hi @thomasmckeown,

The error message tells us the browser module can’t find the browser executable (Chromium/Chrome). Also, the k6 Github action doesn’t yet support running k6-browser tests. There is an open issue about it here. We’re looking into this to come up with a solution :crossed_fingers:

Thanks!

2 Likes

Hi @thomasmckeown,

As Inanc said, the current GH action does not support running browser tests. But here is an alternative way to run them from GH actions:

This example downloads k6 and executes run-tests.sh to run multiple k6 tests. You can use a similar bash script or replace it with your k6 run command. Please note how run-tests.sh sets the required environment variables:

export K6_BROWSER_HEADLESS=true 
export K6_BROWSER_ARGS='no-sandbox' 
if [ "$ACT" = "true" ]; then
	export K6_BROWSER_EXECUTABLE_PATH=/usr/bin/google-chrome
fi

Hope this helps! If you have any additional questions, please don’t hesitate to let us know.

3 Likes