Hello,
I’m having trouble getting a browser test to work. I am running k6 through Docker and have the following Dockerfile:
FROM grafana/k6:latest
USER root
RUN apk update && apk add --no-cache chromium
...
ENV K6_BROWSER_ENABLED=true
ENV LOAD_TEST_TARGET_VU_COUNT=1
ENV LOAD_TEST_SECRET_SEED=1
Here is my test script:
import { sleep, check } from "k6";
import { Rate } from "k6/metrics";
import { chromium } from "k6/experimental/browser";
export const errorRate = new Rate("errors");
export default async function () {
const browser = chromium.launch({
args: ["no-sandbox"],
ignoreDefaultArgs: ["enable-automation"],
headless: true,
timeout: "60s", // Or whatever time you want to define
});
console.log("🚀launching browser");
// I've tried using an explicit context resulting in a similar error
// const context = browser.newContext();
// // const page = context.newPage();
const page = browser.newPage();
console.log("✨new page");
try {
await page.goto("https://somepage.com/login");
let submitButton = page.locator('input[type="submit"]');
...
} finally {
page.screenshot({ path: "screenshot.png" });
page.close();
browser.close();
}
check(true, {
"status is 200": () => true,
}) || errorRate.add(1);
sleep(1);
}
How I build and run the image:
docker build -t browser-k6 -f ./load-test/Dockerfile .
docker run --rm --network="host" -i browser-k6 run - <./load-test/src/test.js
Error:
time="2023-05-08T14:19:04Z" level=error msg="communicating with browser: websocket: close 1006 (abnormal closure): unexpected EOF" category=cdp elapsed="0 ms" goroutine=56
time="2023-05-08T14:19:04Z" level=error msg="process with PID 17 unexpectedly ended: signal: trace/breakpoint trap" category=browser elapsed="6 ms" goroutine=86
time="2023-05-08T14:19:04Z" level=error msg="Uncaught (in promise) GoError: creating new page in browser context: canceled\n\tat github.com/grafana/xk6-browser/browser.mapBrowser.func3 (native)\n\tat file:///-:49:15(26)\n" executor=per-vu-iterations scenario=default
Error when using explicit context:
time="2023-05-08T14:30:00Z" level=error msg="communicating with browser: read tcp 127.0.0.1:57700->127.0.0.1:33765: read: connection reset by peer" category=cdp elapsed="0 ms" goroutine=82
time="2023-05-08T14:30:00Z" level=error msg="process with PID 17 unexpectedly ended: signal: trace/breakpoint trap" category=browser elapsed="5 ms" goroutine=70
time="2023-05-08T14:30:00Z" level=error msg="Uncaught (in promise) GoError: creating new page in browser context: creating a new blank page: read tcp 127.0.0.1:57700->127.0.0.1:33765: read: connection reset by peer\n\tat github.com/grafana/xk6-browser/browser.mapBrowserContext.func4 (native)\n\tat file:///-:48:15(30)\n" executor=per-vu-iterations scenario=default
I’m enjoying using k6, thank you for all your hard work on the library and community. Thank you also for your help ahead of time.