Observing "GoError: launching browser: exec: no command while running browser tests on docker

Dockerfile used to build the image

# syntax=docker/dockerfile:1

FROM debian:bullseye as browser

RUN apt-get update && \
    apt-get install -y chromium

ENV XK6_HEADLESS=true
FROM golang:1.18 as builder

# build k6 0.36.0 with prometheus support
ENV K6_VERSION=v0.36.0
RUN go install go.k6.io/xk6/cmd/xk6@latest && xk6 build --with github.com/grafana/xk6-browser

WORKDIR /build

ENV CGO_ENABLED=0 
ENV GOOS=linux
COPY . .
RUN cd cmd/agent;go build -o /build/runner -mod mod -a .

FROM loadimpact/k6:0.36.0
WORKDIR /home/k6
COPY --from=builder /go/k6 /usr/bin/k6
COPY --from=builder /build/runner /bin/runner
ENTRYPOINT ["/bin/runner"]

Output:
time=“2022-11-15T12:56:55Z” level=error msg=“GoError: launching browser: exec: no command\n\tat reflect.methodValueCall (native)\n\tat file:///data/test-content:11:34(8)\n\tat native\n” executor=per-vu-iterations scenario=default source=stacktrace

Script Used


import { sleep } from 'k6';

import { chromium } from 'k6/x/browser';
import { Counter, Rate, Trend } from "k6/metrics";

//let  timeToFirstByte = new Trend("time_to_first_byte", true);


export default function () {
  const browser = chromium.launch({
    headless: true,  // false if you wish to view the browser
    slowMo: '500ms',
  });

  const context = browser.newContext();
  const page = context.newPage();
  
  
  page.goto('https://test.k6.io/');
  const elem = page.$('a[href="/my_messages.php"]');
  page.screenshot({ path: `example-chromium.png` });
  elem.click();
  sleep(1)
  page.screenshot({ path: `example-chromium1.png` });
  sleep(10);
  page.close();
  browser.close();
}

Could you please let me know how can resolve the "GoError: launching browser: exec: no command " Error and run the browser test in non-gui mode

Hi @chandana194,

Welcome to the forum!

Thanks for your question. We need to get some more information from you to be able to replicate the issue on our side. Could you please fill in the gaps:

  1. What host OS is your computer running on?
  2. What is this agent that you are building and running alongside k6?
  3. Can you give us the exact step-by-step command line instructions as to how you’re building and running the docker image and test?

I tried your test (with some alterations to goto since it is now async) and it worked on my Mac laptop. These are the steps i took:

  1. Clone the xk6-browser github project:
    git clone https://github.com/grafana/xk6-browser.git
    
  2. Create a test file (test.js) in the root of the cloned project and copy the following test into it:
    import { sleep } from 'k6';
    
    import { chromium } from 'k6/x/browser';
    import { Counter, Rate, Trend } from "k6/metrics";
    
    //let  timeToFirstByte = new Trend("time_to_first_byte", true);
    
    export default function () {
      const browser = chromium.launch({
        headless: true,  // false if you wish to view the browser
        slowMo: '500ms',
      });
    
      const context = browser.newContext();
      const page = context.newPage();
      
      page.goto('https://test.k6.io/').then(() => {
        const elem = page.$('a[href="/my_messages.php"]');
        page.screenshot({ path: `example-chromium.png` });
        elem.click();
        sleep(1)
        page.screenshot({ path: `example-chromium1.png` });
        sleep(10);
      }).finally(() => {
        page.close();
        browser.close();
      })
    }
    
  3. Now build and run the test using docker-compose:
    docker-compose run -T xk6-browser run - <test.js
    
  4. It should run the test without any errors.

Cheers,
Ankur