{"id":"5458dc3e9e561f1f","repo":"vitest-dev/vitest","slug":"method-getbyrole-is-not-supported-by-the-prov","errorCode":null,"errorMessage":"Method \"getByRole\" is not supported by the \"${provider}\" provider.","messagePattern":"Method \"getByRole\" is not supported by the \"(.+?)\" provider\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/browser/src/client/tester/context.ts","lineNumber":440,"sourceCode":"          kind: bodyOrOptions?.kind ?? 'mark',\n          stack: bodyOrOptions?.stack ?? error?.stack,\n        })\n      }\n      if (!hasActiveTrace) {\n        return Promise.resolve()\n      }\n      return triggerCommand(\n        '__vitest_markTrace',\n        [{\n          name,\n          stack: bodyOrOptions?.stack ?? error?.stack,\n        }],\n        error,\n      )\n    })\n  },\n  getByRole() {\n    throw new Error(`Method \"getByRole\" is not supported by the \"${provider}\" provider.`)\n  },\n  getByLabelText() {\n    throw new Error(`Method \"getByLabelText\" is not supported by the \"${provider}\" provider.`)\n  },\n  getByTestId() {\n    throw new Error(`Method \"getByTestId\" is not supported by the \"${provider}\" provider.`)\n  },\n  getByAltText() {\n    throw new Error(`Method \"getByAltText\" is not supported by the \"${provider}\" provider.`)\n  },\n  getByPlaceholder() {\n    throw new Error(`Method \"getByPlaceholder\" is not supported by the \"${provider}\" provider.`)\n  },\n  getByText() {\n    throw new Error(`Method \"getByText\" is not supported by the \"${provider}\" provider.`)\n  },\n  getByTitle() {\n    throw new Error(`Method \"getByTitle\" is not supported by the \"${provider}\" provider.`)","sourceCodeStart":422,"sourceCodeEnd":458,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/browser/src/client/tester/context.ts#L422-L458","documentation":"page.getByRole is a throwing stub on the page object (packages/browser/src/client/tester/context.ts:439-441); it is only implemented when locators.extend({ getByRole }) registers a page-level implementation (context.ts:500-506). The default page object does not expose a role-based query at the top level — role queries are available on Locator instances obtained via page.elementLocator(element) (locators.ts:248). The message reports the active provider so you know which provider lacks the page-level shortcut.","triggerScenarios":"Calling page.getByRole('button') directly on the imported page object without first registering a locator extension, or without going through a Locator instance.","commonSituations":"Developers familiar with Playwright's page.getByRole assuming Vitest's page mirrors it; copying testing-library patterns that call getByRole at the top level.","solutions":["Use a Locator: const locator = page.elementLocator(document.body); locator.getByRole('button', { name: 'Save' }).","Register a page-level shortcut via browser.locators.extend({ getByRole: (role, opts) => ... }) if you need the top-level API.","Use the built-in locators from vitest/browser (e.g. const { getByRole } = server or the configured locators)."],"exampleFix":"// before\nconst btn = page.getByRole('button', { name: 'Save' })\n// after\nconst btn = page.elementLocator(document.body).getByRole('button', { name: 'Save' })","handlingStrategy":"type-guard","validationCode":"// Prefer going through a Locator rather than the page-level stub:\nconst root = page.elementLocator(document.body)\nconst btn = root.getByRole('button', { name: 'Save' })","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat page.getByRole as unavailable; always start from page.elementLocator(...).","If you need a top-level helper, register it once via browser.locators.extend in setup."],"tags":["browser","locators","getbyrole","page","unsupported"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}