{"record":{"id":"63be220ee06574d5","repo":"grafana/k6","slug":"missing-required-argument-testid-63be22","errorCode":null,"errorMessage":"missing required argument 'testId'","messagePattern":"missing required argument 'testId'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/browser/locator_mapping.go","lineNumber":273,"sourceCode":"\t\t\t\treturn nil, errors.New(\"missing required argument 'placeholder'\")\n\t\t\t}\n\t\t\tpplaceholder, popts := parseGetByBaseOptions(vu.Context(), placeholder, false, opts)\n\n\t\t\tml := mapLocator(vu, lo.GetByPlaceholder(pplaceholder, popts))\n\t\t\treturn rt.ToValue(ml).ToObject(rt), nil\n\t\t},\n\t\t\"getByRole\": func(role sobek.Value, opts sobek.Value) (*sobek.Object, error) {\n\t\t\tif k6common.IsNullish(role) {\n\t\t\t\treturn nil, errors.New(\"missing required argument 'role'\")\n\t\t\t}\n\t\t\tpopts := parseGetByRoleOptions(vu.Context(), opts)\n\n\t\t\tml := mapLocator(vu, lo.GetByRole(role.String(), popts))\n\t\t\treturn rt.ToValue(ml).ToObject(rt), nil\n\t\t},\n\t\t\"getByTestId\": func(testID sobek.Value) (*sobek.Object, error) {\n\t\t\tif k6common.IsNullish(testID) {\n\t\t\t\treturn nil, errors.New(\"missing required argument 'testId'\")\n\t\t\t}\n\t\t\tptestID := parseStringOrRegex(testID, false)\n\n\t\t\tml := mapLocator(vu, lo.GetByTestID(ptestID))\n\t\t\treturn rt.ToValue(ml).ToObject(rt), nil\n\t\t},\n\t\t\"getByText\": func(text sobek.Value, opts sobek.Value) (*sobek.Object, error) {\n\t\t\tif k6common.IsNullish(text) {\n\t\t\t\treturn nil, errors.New(\"missing required argument 'text'\")\n\t\t\t}\n\t\t\tptext, popts := parseGetByBaseOptions(vu.Context(), text, true, opts)\n\n\t\t\tml := mapLocator(vu, lo.GetByText(ptext, popts))\n\t\t\treturn rt.ToValue(ml).ToObject(rt), nil\n\t\t},\n\t\t\"getByTitle\": func(title sobek.Value, opts sobek.Value) (*sobek.Object, error) {\n\t\t\tif k6common.IsNullish(title) {\n\t\t\t\treturn nil, errors.New(\"missing required argument 'title'\")","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/js/modules/k6/browser/browser/locator_mapping.go#L255-L291","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\nconst btn = page.locator('form').getByTestId(row.testID); // fixture uses 'testId'\n\n// after\nconst btn = page.locator('form').getByTestId(row.testId ?? 'submit-button');","handlingStrategy":"validation","validationCode":"const id = row.testId ?? 'submit-button';\nif (id === undefined || id === null) throw new Error('testId is required');\nconst loc = parent.getByTestId(id);","typeGuard":"function isNonEmptyStringOrRegExp(v) {\n  return (typeof v === 'string' && v.length > 0) || v instanceof RegExp;\n}\n// usage: if (!isNonEmptyStringOrRegExp(id)) throw new Error('testId must be a non-empty string or RegExp');","tryCatchPattern":"try {\n  const loc = parent.getByTestId(id);\n} catch (e) {\n  if (/missing required argument 'testId'/.test(e.message)) throw new Error(`testId missing for row ${i}`);\n  throw e;\n}","preventionTips":["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"],"tags":["browser","locator","test-id","argument-validation","api-misuse"],"backgroundTag":"missing-required-argument","analyzedSha":"8d06114777191d21ef885d05c5f8aa9e1ed838ae","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}