{"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":272,"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":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/browser/locator_mapping.go#L254-L290","documentation":"Locator.getByTestId(testId) in the k6 browser module requires a non-nullish argument; the mapping layer rejects missing, null, or undefined values before calling parseStringOrRegex. The test id (string or RegExp) is matched against the data-testid attribute and is the entire selector within the locator scope. Playwright's method has the same contract.","triggerScenarios":"Calling page.locator('tbody').getByTestId() with no argument, passing null/undefined, or forwarding a selector constant that is undefined after a rename or missing re-export.","commonSituations":"Table row scoping with per-row generated ids, selector-module refactors, helpers receiving an optional id parameter.","solutions":["Pass the test id string or RegExp: page.locator('tbody').getByTestId('row-42')","Verify the constant is imported and defined before use (log it once)","Use a RegExp for generated ids: page.locator('tbody').getByTestId(/^row-\\d+$/)","Fix missing exports or stale names in the selectors module"],"exampleFix":"// before\nconst row = page.locator('tbody').getByTestId(SEL.row); // SEL.row is undefined\n\n// after\nconst row = page.locator('tbody').getByTestId('row-42');","handlingStrategy":"validation","validationCode":"const tid = SEL.row(rowNum);\nif (!isTextSelector(tid)) throw new Error(`test id for row ${rowNum} resolved to nothing`);\nlocator.getByTestId(tid);","typeGuard":"function isTextSelector(v) {\n  return (typeof v === 'string' && v.length > 0) || v instanceof RegExp;\n}","tryCatchPattern":"try {\n  sub = locator.getByTestId(maybeTid);\n} catch (e) {\n  if (/missing required argument 'testId'/.test(String(e.message))) {\n    throw new Error(`testId missing; SEL map lacks an entry for this entity`);\n  }\n  throw e;\n}","preventionTips":["Build test-id strings via a helper that throws when inputs are undefined instead of returning undefined","Freeze the selectors module and add a startup check for every referenced key","Use RegExp test ids for rows/items with generated numeric suffixes","Re-run page-object smoke tests after renaming any selector constant"],"tags":["browser","locator","argument-validation","get-by","test-id"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}