vitest-dev/vitest · error · Error

Method "getByRole" is not supported by the

Error message

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

What it means

page.getByRole is part of the locator API that is only implemented by full browser-automation providers (Playwright/WebDriverIO). The default page object stubs these methods to throw, naming the active provider so the user knows the call is unsupported in their configuration. The stubs are overridden by provider.extend() when a real provider is installed.

Solutions

  1. Switch test.browser.provider to 'playwright' or 'webdriverio' and install the matching provider package.
  2. If you must stay on preview, use raw DOM queries (document.querySelector) instead of getByRole.
  3. Verify locators are registered via page.extend or that the provider plugin loaded by checking getBrowserState().provider.

Example fix

// before
const btn = page.getByRole('button', { name: 'Save' })
// after (preview provider)
const btn = document.querySelector('button')!  // or switch provider to 'playwright'
Defensive patterns

Strategy: validation

Validate before calling

if (getBrowserState().provider === 'preview') {
  // use document.querySelector instead of page.getByRole
} else {
  page.getByRole('button', { name: 'Save' })
}

Type guard

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

Prevention

When it happens

Trigger: Calling page.getByRole(...) while provider is 'preview' (or any provider that did not register locators); accessing locators before the provider plugin has loaded; running in a stripped-down custom provider that omits locator methods.

Common situations: Default browser config without provider: 'playwright'; copying locator examples from docs into a preview-provider project; partial provider setup where only some locator methods are wired.

Related errors


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

Appendix: source

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

          kind: bodyOrOptions?.kind ?? 'mark',
          stack: bodyOrOptions?.stack ?? error?.stack,
        })
      }
      if (!hasActiveTrace) {
        return Promise.resolve()
      }
      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.`)

View on GitHub (pinned to 1fa9837ec2)