{"record":{"id":"e3f6c6990ad20586","repo":"grafana/k6","slug":"missing-required-argument-testid-e3f6c6","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/page_mapping.go","lineNumber":218,"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, p.GetByPlaceholder(pplaceholder, 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'\")\n\t\t\t}\n\t\t\tptitle, popts := parseGetByBaseOptions(vu.Context(), title, false, opts)\n\n\t\t\tml := mapLocator(vu, p.GetByTitle(ptitle, 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, p.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, p.GetByText(ptext, popts))\n\t\t\treturn rt.ToValue(ml).ToObject(rt), nil\n\t\t},\n\t\t\"goto\": func(url string, opts sobek.Value) (*sobek.Promise, error) {\n\t\t\tgopts := common.NewFrameGotoOptions(\n\t\t\t\tp.Referrer(),","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/browser/page_mapping.go#L200-L236","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\npage.getByTestId();\n\n// after\npage.getByTestId('submit-button');","handlingStrategy":"validation","validationCode":"if (testId === undefined || testId === null) {\n  throw new Error(`page.getByTestId: 'testId' is required, got ${testId}`);\n}\nconst loc = page.getByTestId(testId);","typeGuard":"function isTestId(v) {\n  return typeof v === 'string' || v instanceof RegExp;\n}","tryCatchPattern":"try {\n  page.getByTestId(testId);\n} catch (e) {\n  if (!e.message.includes(\"missing required argument 'testId'\")) throw e;\n  throw new Error(`test id constant missing from constants module`);\n}","preventionTips":["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"],"tags":["browser","page","getbytestid","locator","argument-validation"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}