{"record":{"id":"8ea3a994693b8f24","repo":"grafana/k6","slug":"missing-required-argument-testid-8ea3a9","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/frame_mapping.go","lineNumber":176,"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, f.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, f.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, f.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, f.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":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/browser/frame_mapping.go#L158-L194","documentation":"Frame.getByTestId(testId) on a k6 browser Frame 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 constitutes the entire selector. Playwright's method has the same contract.","triggerScenarios":"Calling frame.getByTestId() with no argument, passing null/undefined, or forwarding a selector constant that is undefined due to a rename or missing re-export.","commonSituations":"Centralized selector modules after refactoring, generated test ids with dynamic suffixes handled incorrectly, or assertion helpers receiving an optional id.","solutions":["Pass the test id string or RegExp: frame.getByTestId('cart-item-42')","Verify the selector constant is imported and defined (console.log it before use)","Use a RegExp for generated ids: frame.getByTestId(/^cart-item-\\d+$/)","Fix missing exports or renamed constants in the selectors module"],"exampleFix":"// before\nimport { TID } from './selectors.js';\nconst item = page.frame('#shop').getByTestId(TID.cartItem); // undefined after a rename\n\n// after\nconst item = page.frame('#shop').getByTestId('cart-item');","handlingStrategy":"validation","validationCode":"const tid = SEL[entity];\nif (!isTextSelector(tid)) throw new Error(`SEL.${entity} is missing or empty`);\nframe.getByTestId(tid);","typeGuard":"function isTextSelector(v) {\n  return (typeof v === 'string' && v.length > 0) || v instanceof RegExp;\n}","tryCatchPattern":"try {\n  loc = frame.getByTestId(maybeTid);\n} catch (e) {\n  if (/missing required argument 'testId'/.test(String(e.message))) {\n    throw new Error(`testId missing for entity '${entity}'; selector map may be stale`);\n  }\n  throw e;\n}","preventionTips":["Guard dynamic selector lookups: check Object.prototype.hasOwnProperty.call(SEL, entity) before use","Export selectors from one module and unit-check keys used by tests","Use RegExp ids for generated attributes instead of concatenating possibly-undefined parts","Rerun selector smoke tests after DOM or refactoring changes"],"tags":["browser","frame","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"}