vitest-dev/vitest · error · Error

Method "getByText" is not supported by the "${provider}" pro

Error message

Method "getByText" is not supported by the "${provider}" provider.

What it means

page.getByText is a throwing stub (packages/browser/src/client/tester/context.ts:454-455). Text-content queries are available only on Locator instances (getElementLocatorSelectors wires locator.getByText at context.ts:519). The page-level call throws.

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 d568f8ce37)

Solutions

  1. Use a Locator: page.elementLocator(document.body).getByText('Welcome').
  2. Register page.getByText via browser.locators.extend(...) for a top-level shortcut.

Example fix

// before
const heading = page.getByText('Welcome back')
// after
const heading = page.elementLocator(document.body).getByText('Welcome back')
Defensive patterns

Strategy: type-guard

Validate before calling

const root = page.elementLocator(document.body)
const heading = root.getByText('Welcome')

Prevention

When it happens

Trigger: Calling page.getByText('Welcome') directly on the page object.

Common situations: The most common porting mistake: testing-library getByText and Playwright page.getByText both exist, so users expect it on Vitest's page.

Related errors


AI-assisted analysis of vitest-dev/vitest@d568f8ce37 (2026-08-03). Data as JSON: /data/errors/f0898dda2be149c3.json. Report an issue: GitHub.