grafana/k6 · error

missing required argument 'role'

Error message

missing required argument 'role'

What it means

Frame.getByRole(role, options) on a k6 browser Frame requires a non-nullish first argument naming an ARIA role; the mapping in frame_mapping.go throws before options are parsed or CDP is touched. The role string (e.g. 'button', 'heading') is the primary locator input; options such as name or level refine but never replace it. This matches Playwright's mandatory role contract.

Source

Thrown at internal/js/modules/k6/browser/browser/frame_mapping.go:167

				return nil, errors.New("missing required argument 'label'")
			}
			plabel, popts := parseGetByBaseOptions(vu.Context(), label, true, opts)

			ml := mapLocator(vu, f.GetByLabel(plabel, popts))
			return rt.ToValue(ml).ToObject(rt), nil
		},
		"getByPlaceholder": func(placeholder sobek.Value, opts sobek.Value) (*sobek.Object, error) {
			if k6common.IsNullish(placeholder) {
				return nil, errors.New("missing required argument 'placeholder'")
			}
			pplaceholder, popts := parseGetByBaseOptions(vu.Context(), placeholder, false, opts)

			ml := mapLocator(vu, f.GetByPlaceholder(pplaceholder, popts))
			return rt.ToValue(ml).ToObject(rt), nil
		},
		"getByRole": func(role sobek.Value, opts sobek.Value) (*sobek.Object, error) {
			if k6common.IsNullish(role) {
				return nil, errors.New("missing required argument 'role'")
			}
			popts := parseGetByRoleOptions(vu.Context(), opts)

			ml := mapLocator(vu, f.GetByRole(role.String(), popts))
			return rt.ToValue(ml).ToObject(rt), nil
		},
		"getByTestId": func(testID sobek.Value) (*sobek.Object, error) {
			if k6common.IsNullish(testID) {
				return nil, errors.New("missing required argument 'testId'")
			}
			ptestID := parseStringOrRegex(testID, false)

			ml := mapLocator(vu, f.GetByTestID(ptestID))
			return rt.ToValue(ml).ToObject(rt), nil
		},
		"getByText": func(text sobek.Value, opts sobek.Value) (*sobek.Object, error) {
			if k6common.IsNullish(text) {
				return nil, errors.New("missing required argument 'text'")

View on GitHub (pinned to 93accf6570)

Solutions

  1. Pass an ARIA role string first: frame.getByRole('heading', { name: 'Dashboard' })
  2. Keep the accessible name in options rather than dropping the role argument
  3. Validate/default the role variable from test data before the call
  4. Check for typos in the constant or property supplying the role

Example fix

// before
const h = page.frame('#content').getByRole(roleVar, { name: 'Overview' }); // roleVar is undefined

// after
const h = page.frame('#content').getByRole('heading', { name: 'Overview' });
Defensive patterns

Strategy: validation

Validate before calling

if (!isAriaRole(roleVar)) throw new Error(`valid ARIA role required, got: ${roleVar}`);
frame.getByRole(roleVar, opts);

Type guard

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']);
function isAriaRole(v) {
  return typeof v === 'string' && ARIA_ROLES.has(v);
}

Try / catch

try {
  loc = frame.getByRole(maybeRole, opts);
} catch (e) {
  if (/missing required argument 'role'/.test(String(e.message))) {
    throw new Error('role argument missing; accessible name belongs in options');
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling frame.getByRole() with no role, passing null/undefined, or intending to select by accessible name only and passing undefined while putting the name in options.

Common situations: Role/name confusion when porting from getByRole('button', { name }) examples, data-driven role lists with gaps, optional role parameters in shared helpers.

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/2274846ec664de53. Report an issue: GitHub.