grafana/k6 · error
missing required argument 'testId'
Error message
missing required argument 'testId'
What it means
Thrown by locator.getByTestId() in the k6 browser module (internal/js/modules/k6/browser/browser/locator_mapping.go:272). The testID argument (string or RegExp, matched against the data-testid attribute unless testIdAttribute is reconfigured) is mandatory; the nullish guard rejects nil/undefined/null before parseStringOrRegex runs, because the internal ID selector cannot be constructed without it.
Solutions
- Pass a string or RegExp: page.locator('form').getByTestId('submit-button')
- Default the value first: const id = row.testId ?? 'submit-button'
- If your app uses a different attribute, set it via the browser context options (testIdAttribute) rather than omitting the argument
- Verify the fixture field name spelling matches what the script destructures
Example fix
// before
const btn = page.locator('form').getByTestId(row.testID); // fixture uses 'testId'
// after
const btn = page.locator('form').getByTestId(row.testId ?? 'submit-button'); Defensive patterns
Strategy: validation
Validate before calling
const id = row.testId ?? 'submit-button';
if (id === undefined || id === null) throw new Error('testId is required');
const loc = parent.getByTestId(id); Type guard
function isNonEmptyStringOrRegExp(v) {
return (typeof v === 'string' && v.length > 0) || v instanceof RegExp;
}
// usage: if (!isNonEmptyStringOrRegExp(id)) throw new Error('testId must be a non-empty string or RegExp'); Try / catch
try {
const loc = parent.getByTestId(id);
} catch (e) {
if (/missing required argument 'testId'/.test(e.message)) throw new Error(`testId missing for row ${i}`);
throw e;
} Prevention
- Centralize test IDs in one selectors module and assert the key exists before use
- Default dynamic IDs with ?? instead of passing possibly-undefined values
- If the app uses data-test/data-qa, set testIdAttribute in context options rather than omitting the argument
- Validate fixture columns at init so empty test IDs fail early
When it happens
Trigger: Calling parent.getByTestId() with no arguments; passing an explicitly null/undefined value; passing testID from an object property that does not exist (obj['data-test'] vs obj.testId).
Common situations: Test IDs sourced from JSON fixtures or spreadsheets with missing cells; teams migrating selectors from data-test to data-testid naming; destructuring that misnames the field; copy-paste of a getByTestId call with the argument left off.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- missing required argument 'placeholder'
- missing required argument 'role'
- missing required argument 'testId'
- missing required argument 'text'
- missing required argument 'title'
AI-assisted analysis of grafana/k6@8d06114777 (2026-08-18).
Data as JSON: /api/errors/63be220ee06574d5.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/browser/locator_mapping.go:273
return nil, errors.New("missing required argument 'placeholder'")
}
pplaceholder, popts := parseGetByBaseOptions(vu.Context(), placeholder, false, opts)
ml := mapLocator(vu, lo.GetByPlaceholder(pplaceholder, popts))
return rt.ToValue(ml).ToObject(rt), nil
},
"getByRole": func(role sobek.Value, opts sobek.Value) (*sobek.Object, error) {
if k6common.IsNullish(role) {
return nil, errors.New("missing required argument 'role'")
}
popts := parseGetByRoleOptions(vu.Context(), opts)
ml := mapLocator(vu, lo.GetByRole(role.String(), 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, lo.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, lo.GetByText(ptext, 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'")View on GitHub (pinned to 8d06114777)