{"record":{"id":"5b3a9865f4b5303f","repo":"grafana/k6","slug":"missing-required-argument-role-5b3a98","errorCode":null,"errorMessage":"missing required argument 'role'","messagePattern":"missing required argument 'role'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/browser/page_mapping.go","lineNumber":173,"sourceCode":"\t\t\"getAttribute\": func(selector string, name string, opts sobek.Value) (*sobek.Promise, error) {\n\t\t\tpopts := common.NewFrameBaseOptions(p.MainFrame().Timeout())\n\t\t\tif err := popts.Parse(vu.Context(), opts); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing getAttribute options: %w\", err)\n\t\t\t}\n\t\t\treturn promise(vu, func() (any, error) {\n\t\t\t\ts, ok, err := p.GetAttribute(selector, name, popts)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, err //nolint:wrapcheck\n\t\t\t\t}\n\t\t\t\tif !ok {\n\t\t\t\t\treturn nil, nil //nolint:nilnil\n\t\t\t\t}\n\t\t\t\treturn s, nil\n\t\t\t}), 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, p.GetByRole(role.String(), popts))\n\t\t\treturn rt.ToValue(ml).ToObject(rt), nil\n\t\t},\n\t\t\"getByAltText\": func(alt sobek.Value, opts sobek.Value) (*sobek.Object, error) {\n\t\t\tif k6common.IsNullish(alt) {\n\t\t\t\treturn nil, errors.New(\"missing required argument 'altText'\")\n\t\t\t}\n\t\t\tpalt, popts := parseGetByBaseOptions(vu.Context(), alt, false, opts)\n\n\t\t\tml := mapLocator(vu, p.GetByAltText(palt, popts))\n\t\t\treturn rt.ToValue(ml).ToObject(rt), nil\n\t\t},\n\t\t\"getByLabel\": func(label sobek.Value, opts sobek.Value) (*sobek.Object, error) {\n\t\t\tif k6common.IsNullish(label) {\n\t\t\t\treturn nil, errors.New(\"missing required argument 'label'\")","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/browser/page_mapping.go#L155-L191","documentation":"Thrown by the Page mapping's getByRole method in k6's browser module. The ARIA role is the mandatory first argument; the mapping rejects nullish values with k6common.IsNullish before parsing role options and calling p.GetByRole. Note that any non-nullish value is coerced with role.String(), so only null/undefined hit this error.","triggerScenarios":"page.getByRole() with no arguments; page.getByRole(null); passing opts in the first position by mistake: page.getByRole({ name: 'Submit' }).","commonSituations":"Copy-pasting Playwright examples and trimming the role; building the role from a variable that is unset; assuming name alone identifies the element (name belongs in opts, role must still be first).","solutions":["Always pass the role string first: page.getByRole('button', { name: 'Submit' })","If role is dynamic, guard it: role ? page.getByRole(role, opts) : failFast()","Remember options like name/exact go in the SECOND argument, never replace the first"],"exampleFix":"// before\npage.getByRole({ name: 'Submit' });\n\n// after\npage.getByRole('button', { name: 'Submit' });","handlingStrategy":"validation","validationCode":"if (typeof role !== 'string' || role.length === 0) {\n  throw new Error(`page.getByRole: 'role' string is required, got ${role}`);\n}\nconst loc = page.getByRole(role, opts);","typeGuard":"function isRole(v) {\n  return typeof v === 'string' && v.length > 0;\n}","tryCatchPattern":"try {\n  page.getByRole(role);\n} catch (e) {\n  if (!e.message.includes(\"missing required argument 'role'\")) throw e;\n  throw new Error(`role must be first arg; name goes in opts`);\n}","preventionTips":["Memorize the signature: getByRole(role, { name, exact }) — role always first","Use TypeScript/JSDoc types on shared helper functions so nullish roles are caught statically"],"tags":["browser","page","getbyrole","locator","aria","argument-validation"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}