vitest-dev/vitest · error · Error

Method "getByTestId" is not supported by the "${provider}" p

Error message

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

What it means

page.getByTestId is a throwing stub (packages/browser/src/client/tester/context.ts:445-446). Test-id queries at the page level aren't implemented by default; the Locator class implements getByTestId (locators.ts:265) using server.config.browser.locators.testIdAttribute. Calling the page-level stub throws.

Source

Thrown at packages/browser/src/client/tester/context.ts:446

      }
      return triggerCommand(
        '__vitest_markTrace',
        [{
          name,
          stack: bodyOrOptions?.stack ?? error?.stack,
        }],
        error,
      )
    })
  },
  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.`)

View on GitHub (pinned to d568f8ce37)

Solutions

  1. Use a Locator: page.elementLocator(document.body).getByTestId('submit').
  2. If you renamed the test id attribute (data-testid -> data-test), configure browser.locators.testIdAttribute and still query through a Locator.
  3. Register page.getByTestId via browser.locators.extend(...) if a top-level shortcut is required.

Example fix

// before
const el = page.getByTestId('submit')
// after
const el = page.elementLocator(document.body).getByTestId('submit')
Defensive patterns

Strategy: type-guard

Validate before calling

const root = page.elementLocator(document.body)
const el = root.getByTestId('submit')

Prevention

When it happens

Trigger: Calling page.getByTestId('submit') on the page object directly, with no registered extension.

Common situations: Assuming Vitest's page mirrors Playwright's page.getByTestId; importing page and calling getByTestId before setting up locators.

Related errors


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