grafana/k6 · error
missing required argument 'testId'
Error message
missing required argument 'testId'
What it means
Thrown by the Page mapping's getByTestId method. Unlike other getBy* methods it takes a single mandatory argument (no options); the mapping checks it with k6common.IsNullish and parses it with parseStringOrRegex. Omitting it or passing null/undefined fails here.
Source
Thrown at internal/js/modules/k6/browser/browser/page_mapping.go:218
return nil, errors.New("missing required argument 'placeholder'")
}
pplaceholder, popts := parseGetByBaseOptions(vu.Context(), placeholder, false, opts)
ml := mapLocator(vu, p.GetByPlaceholder(pplaceholder, popts))
return rt.ToValue(ml).ToObject(rt), nil
},
"getByTitle": func(title sobek.Value, opts sobek.Value) (*sobek.Object, error) {
if k6common.IsNullish(title) {
return nil, errors.New("missing required argument 'title'")
}
ptitle, popts := parseGetByBaseOptions(vu.Context(), title, false, opts)
ml := mapLocator(vu, p.GetByTitle(ptitle, popts))
return rt.ToValue(ml).ToObject(rt), nil
},
"getByTestId": func(testID sobek.Value) (*sobek.Object, error) {
if k6common.IsNullish(testID) {
return nil, errors.New("missing required argument 'testId'")
}
ptestID := parseStringOrRegex(testID, false)
ml := mapLocator(vu, p.GetByTestID(ptestID))
return rt.ToValue(ml).ToObject(rt), nil
},
"getByText": func(text sobek.Value, opts sobek.Value) (*sobek.Object, error) {
if k6common.IsNullish(text) {
return nil, errors.New("missing required argument 'text'")
}
ptext, popts := parseGetByBaseOptions(vu.Context(), text, true, opts)
ml := mapLocator(vu, p.GetByText(ptext, popts))
return rt.ToValue(ml).ToObject(rt), nil
},
"goto": func(url string, opts sobek.Value) (*sobek.Promise, error) {
gopts := common.NewFrameGotoOptions(
p.Referrer(),View on GitHub (pinned to 93accf6570)
Solutions
- Pass the test id string or RegExp: page.getByTestId('submit-button')
- Validate the id source: page.getByTestId(testId ?? 'submit-button'), or assert testId is truthy first
- Note there is no options argument for getByTestId — the id must be the first and only argument
Example fix
// before
page.getByTestId();
// after
page.getByTestId('submit-button'); Defensive patterns
Strategy: validation
Validate before calling
if (testId === undefined || testId === null) {
throw new Error(`page.getByTestId: 'testId' is required, got ${testId}`);
}
const loc = page.getByTestId(testId); Type guard
function isTestId(v) {
return typeof v === 'string' || v instanceof RegExp;
} Try / catch
try {
page.getByTestId(testId);
} catch (e) {
if (!e.message.includes("missing required argument 'testId'")) throw e;
throw new Error(`test id constant missing from constants module`);
} Prevention
- Define all data-testid values in one frozen constants object; a typo then fails your lint/CI, not the browser run
- Remember getByTestId takes exactly one argument — no options
When it happens
Trigger: page.getByTestId() with no arguments; page.getByTestId(undefined) when the test-id constant is misspelled or unset; calling it with (null, opts) assuming options exist.
Common situations: data-testid values maintained in a separate constants file with gaps; Playwright ports where getByTestId was given an empty string; refactors that pass the id via the wrong variable.
Related errors
- missing required argument 'role'
- missing required argument 'altText'
- missing required argument 'label'
- missing required argument 'placeholder'
- missing required argument 'title'
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/e3f6c6990ad20586.
Report an issue: GitHub.