{"record":{"id":"99d51139c5035fb3","repo":"grafana/k6","slug":"missing-required-argument-role-99d511","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/locator_mapping.go","lineNumber":263,"sourceCode":"\t\t\t\treturn nil, errors.New(\"missing required argument 'label'\")\n\t\t\t}\n\t\t\tplabel, popts := parseGetByBaseOptions(vu.Context(), label, true, opts)\n\n\t\t\tml := mapLocator(vu, lo.GetByLabel(plabel, popts))\n\t\t\treturn rt.ToValue(ml).ToObject(rt), nil\n\t\t},\n\t\t\"getByPlaceholder\": func(placeholder sobek.Value, opts sobek.Value) (*sobek.Object, error) {\n\t\t\tif k6common.IsNullish(placeholder) {\n\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'\")","sourceCodeStart":245,"sourceCodeEnd":281,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/browser/locator_mapping.go#L245-L281","documentation":"Locator.getByRole(role, options) in the k6 browser module requires a non-nullish first argument naming an ARIA role; the mapping in locator_mapping.go throws before options are parsed. The role string is the primary selector input — options like name, checked, or level only refine the match. Playwright's getByRole is equally strict.","triggerScenarios":"Calling page.locator('nav').getByRole() with no role, passing null/undefined, or moving the intended criterion into options ({ name: 'Home' }) while leaving the role undefined.","commonSituations":"Porting getByRole examples and dropping the role token, data-driven role configurations with gaps, optional role parameters in shared helpers.","solutions":["Pass an ARIA role string first: page.locator('nav').getByRole('link', { name: 'Home' })","Keep accessible-name criteria in options, not as a replacement for the role argument","Validate/default the role variable before the call","Verify the role constant or property is defined where it is declared"],"exampleFix":"// before\nconst home = page.locator('nav').getByRole(roleVar, { name: 'Home' }); // roleVar is undefined\n\n// after\nconst home = page.locator('nav').getByRole('link', { name: 'Home' });","handlingStrategy":"validation","validationCode":"if (!isAriaRole(role)) throw new Error(`getByRole needs a valid ARIA role, got: ${role}`);\nlocator.getByRole(role, opts);","typeGuard":"const ARIA_ROLES = new Set(['button','link','textbox','checkbox','radio','heading','img','list','listitem','navigation','main','banner','contentinfo','form','table','row','cell','dialog','alert','search','tab','tablist','option','combobox','menuitem','progressbar','slider','switch']);\nfunction isAriaRole(v) {\n  return typeof v === 'string' && ARIA_ROLES.has(v);\n}","tryCatchPattern":"try {\n  sub = locator.getByRole(maybeRole, opts);\n} catch (e) {\n  if (/missing required argument 'role'/.test(String(e.message))) {\n    throw new Error('role must come first; use { name } in options for accessible names');\n  }\n  throw e;\n}","preventionTips":["Fix the signature in muscle memory: getByRole(role, options)","Validate role values in data-driven suites against the ARIA role set","Do not allow helper functions to default the role parameter to undefined","Diff ported Playwright code against the original when copy-pasting role locators"],"tags":["browser","locator","argument-validation","get-by","aria"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}