Error when executing script in browser with vus

Hello,

When I run my test script specifying vus and duration I get the following error:

CMD: k6 run --vus 2 --duration 10s script2.js

Errors:

ERRO[0000] Uncaught (in promise) GoError: browser not found in registry. make sure to set browser type option in scenario definition in order to use the browser module default at github.com/grafana/xk6-browser/browser.mapBrowser.func6 (native)

My code:

import { htmlReport } from “K6 Load Test: <%= title %>”;
import { browser } from ‘k6/experimental/browser’;
import { check } from ‘k6’

export const options = {
scenarios: {
ui: {
executor: ‘shared-iterations’,
options: {
browser: {
type: ‘chromium’
}
}
}
}
}

export default async function () {
const page = browser.newPage()

await page.goto(‘https://otel-demo.field-eng.grafana.net/’)

const productCard = page.locator(‘(//div[@data-cy=“product-card”])[1]’)
await productCard.click()

const quantityOption = page.locator(‘[data-cy=“product-quantity”]’)
quantityOption.selectOption(‘3’)

const addToCardBtn = page.locator(‘[data-cy=“product-add-to-cart”]’)
await addToCardBtn.click()

check(page, {
‘cart item name’: page => page.locator(‘//p[text()=“National Park Foundation Explorascope”]’).isVisible() === true,
‘cart item quantity’: page => page.locator(‘//p[text()=“3”]’).isVisible() === true
})

page.close()
}

export function handleSummary(data) {
return {
‘TestSummaryReport.html’: htmlReport(data, { debug: true })
};
}

If I run it normally without specifying vus and duration, the error doesn’t occur.

I did not find anything similar here on the forum, I will be very happy to receive help.

Hi @fsimoneto

The issue here is that using the --vus cmdline argument will overwrite the scenarios definition, and because now the browser module requires a scenario to be defined along with the browser type option, using --vus arg will overwrite the explicit definition that is required to run browser tests. See this issue for more info.

We plan on improving the scenario definition requirement for browser tests. But, as of now, in order to fix this you’ll have to specify the VUs in the scenario definition.

1 Like