vitest-dev/vitest · error · Error
Method "getByText" is not supported by the
Error message
Method "getByText" is not supported by the "${provider}" provider. What it means
page.getByText is a locator method only available with a full browser provider. The default page stub throws, naming the active provider. Text-based location needs provider selector engines (Playwright's text engine) which the preview provider does not provide.
Solutions
- Switch test.browser.provider to 'playwright' or 'webdriverio'.
- Under preview, locate via XPath or a text-walking helper (e.g. Array.from(document.querySelectorAll('*')).find(e => e.textContent?.includes('Submit'))).
- Register the method yourself via page.extend for a custom provider.
Example fix
// before
const node = page.getByText('Submit')
// after (preview provider)
const node = Array.from(document.querySelectorAll('button, a, span')).find(e => e.textContent === 'Submit')! Defensive patterns
Strategy: validation
Validate before calling
if (getBrowserState().provider === 'preview') {
Array.from(document.querySelectorAll('*')).find(e => e.textContent === 'Submit')
} else {
page.getByText('Submit')
} Type guard
function supportsLocators(): boolean {
return ['playwright', 'webdriverio'].includes(getBrowserState().provider ?? '')
} Prevention
- Use a full provider for text-based location.
- Provide a text-walk fallback under preview.
- Keep provider-specific code paths documented.
When it happens
Trigger: Calling page.getByText('Submit') while provider is 'preview' or any provider that has not registered the method via page.extend.
Common situations: i18n/content tests ported from Playwright or Testing Library; default provider config; partial provider registration.
Related errors
- Method "elementLocator" is not supported by the
- Method "frameLocator" is not supported by the
- Method "getByAltText" is not supported by the
- Method "getByLabelText" is not supported by the
- Method "getByPlaceholder" is not supported by the
AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11).
Data as JSON: /api/errors/f0898dda2be149c3.
Report an issue: GitHub.
Appendix: source
Thrown at packages/browser/src/client/tester/context.ts:455
})
},
getByRole() {
throw new Error(`Method "getByRole" is not supported by the "${provider}" provider.`)
},
getByLabelText() {
throw new Error(`Method "getByLabelText" is not supported by the "${provider}" provider.`)
},
getByTestId() {
throw new Error(`Method "getByTestId" is not supported by the "${provider}" provider.`)
},
getByAltText() {
throw new Error(`Method "getByAltText" is not supported by the "${provider}" provider.`)
},
getByPlaceholder() {
throw new Error(`Method "getByPlaceholder" is not supported by the "${provider}" provider.`)
},
getByText() {
throw new Error(`Method "getByText" is not supported by the "${provider}" provider.`)
},
getByTitle() {
throw new Error(`Method "getByTitle" is not supported by the "${provider}" provider.`)
},
elementLocator() {
throw new Error(`Method "elementLocator" is not supported by the "${provider}" provider.`)
},
frameLocator() {
throw new Error(`Method "frameLocator" is not supported by the "${provider}" provider.`)
},
extend(methods) {
for (const key in methods) {
(page as any)[key] = (methods as any)[key].bind(page)
}
return page
},
}
View on GitHub (pinned to 1fa9837ec2)