vitest-dev/vitest · error · Error

Method "getByTestId" is not supported by the

Error message

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

What it means

page.getByTestId is a locator method that requires a full provider. The default page stub throws, naming the active provider, when getByTestId is invoked without a registered implementation. Test IDs are provider-specific selectors (Playwright uses testid engines), so preview cannot satisfy the call.

Solutions

  1. Switch provider to 'playwright' or 'webdriverio' and install the matching package.
  2. Under preview, query directly: document.querySelector('[data-testid="submit"]').
  3. Set test.browser.locators.testIdAttribute if your test IDs use a custom attribute.

Example fix

// before
const el = page.getByTestId('submit')
// after (preview provider)
const el = document.querySelector('[data-testid="submit"]')!
Defensive patterns

Strategy: validation

Validate before calling

if (getBrowserState().provider === 'preview') {
  document.querySelector('[data-testid="submit"]')
} else {
  page.getByTestId('submit')
}

Type guard

function supportsLocators(): boolean {
  return ['playwright', 'webdriverio'].includes(getBrowserState().provider ?? '')
}

Prevention

When it happens

Trigger: Calling page.getByTestId('submit') under the preview provider; using the data-testid convention while provider is preview; calling before the provider plugin registered the method.

Common situations: Component tests migrated from @testing-library that rely on getByTestId; default provider config; missing provider install.

Related errors


AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11). Data as JSON: /api/errors/96846922697faf37. Report an issue: GitHub.

Appendix: 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 1fa9837ec2)